public static int[] RandomizeNumberOrder(int n) // var randomArray:array of word); { int[] randomArray = new int[n]; for (int i = 0; i < n; i++) { randomArray[i] = i; // integers in ascending order } //{ randomize;}{do NOT randomize. Instead Initialise RANDSEED in order to get // the same 10 sets of random numbers for each simulation of 10 repeats} RandomNumber rn = new RandomNumber(); int r; //: word; {a random number between 0 and k-1} int dummy; // : word; {holder for random number} for (int k = n - 1; k >= 0; k--) { r = rn.GetInt(k); //a random integer between 0 and k dummy = randomArray[k]; randomArray[k] = randomArray[r]; randomArray[r] = dummy; } return randomArray; } //end of RandomizeNumberOrder()
public static void Main() { Console.WriteLine("Random float:"); Console.WriteLine(RandomNumber.GetFloat()); Console.WriteLine(RandomNumber.GetFloat()); Console.WriteLine(RandomNumber.GetFloat()); Console.WriteLine("Random int, 0 to 200:"); Console.WriteLine(RandomNumber.GetInt(200)); Console.WriteLine(RandomNumber.GetInt(200)); Console.WriteLine(RandomNumber.GetInt(200)); Console.WriteLine("Random int, 100 to 160:"); Console.WriteLine(RandomNumber.GetInt(100, 160)); Console.WriteLine(RandomNumber.GetInt(100, 160)); Console.WriteLine(RandomNumber.GetInt(100, 160)); }