**Next:**In the Main entry point, we use the Shuffle(T) method on integers and strings. It is equally effective on all types.

Based on:.NET 4.5C# program that implements generic Fisher-Yates shuffleusing System; class Program {/// <summary> /// Used in Shuffle(T). /// </summary>static Random _random = new Random();/// <summary> /// Shuffle the array. /// </summary> /// <typeparam name="T">Array element type.</typeparam> /// <param name="array">Array to shuffle.</param>static voidShuffle<T>(T[] array) { int n = array.Length; for (int i = 0; i < n; i++) {// NextDouble returns a random number between 0 and 1. // ... It is equivalent to Math.random() in Java.int r = i + (int)(_random.NextDouble() * (n - i)); T t = array[r]; array[r] = array[i]; array[i] = t; } } static void Main() { { int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; Shuffle(array); foreach (int value in array) { Console.WriteLine(value); } } { string[] array = { "dot", "net", "perls" }; Shuffle(array); foreach (string value in array) { Console.WriteLine(value); } } } }Output6 8 2 7 4 3 5 9 1 net perls dot

**Princeton:**This code the same as the Java shuffle algorithm from the Princeton computer science introductory course.

**Math.random:**In Java, the Math.random method returns a double between 0 and 1. The NextDouble method in C# is equivalent.

**Note:**Thanks to Darrin Henning for pointing out that the previous algorithm was incorrect.

**So:**Currently the method is based on that from a CS textbook used at Princeton University.

**Caution:**The linked implementation is likely much slower than Fisher-Yates in the C# language.