Mega Code Archive

 
Categories / C# Book / 02 Essential Types
 

0329 Random

The Random class generates a pseudorandom sequence of random bytes, integers, or doubles. To use Random, you can optionally provide a seed to initiate the random number series. Using the same seed guarantees the same series of numbers. using System; using System.Numerics; class Sample { public static void Main() { Random r1 = new Random(1); Random r2 = new Random(1); Console.WriteLine(r1.Next(100) + ", " + r1.Next(100)); Console.WriteLine(r2.Next(100) + ", " + r2.Next(100)); } } The output: 24, 11 24, 11