Advertisement
stanevplamen

02.05.02RandomGeneration

Jul 30th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3.  
  4. class RandomGeneration
  5. {
  6.     public static int NextInt()
  7.     {
  8.         Random randomInt = new Random();
  9.         int x = randomInt.Next(100, 200);
  10.         int t = (x ^ (x << 11));
  11.         int w = randomInt.Next(100, 200);
  12.         checked
  13.         {
  14.             int result = (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
  15.             return result;
  16.         }
  17.     }
  18.  
  19.     static void Main()
  20.     {
  21.         Console.WriteLine("Ten random numbers in the interval [100, 200] are: ");
  22.         int numbersToGenerate = 10;
  23.         Random random = new Random();
  24.         int minimum = random.Next(100, 200);
  25.         int maximum = minimum + random.Next(100, 200);
  26.  
  27.         for (int i = 1; i <= numbersToGenerate; i++)
  28.         {
  29.             checked
  30.             {
  31.                 double newRandom = ((random.NextDouble() * (maximum - minimum) + minimum) * NextInt()) % 100 + 100;
  32.                 Console.WriteLine("{0:0.00}", newRandom);
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement