System.Random

This class provides an implementation of a pseudo-random number generator. System.Random makes it easy to generate numbers that are statistically close to random. Listing B.15 shows how to use the Random class (random.cs).

Listing B.15. Random Example
 static void Main(string [] args) { Random r = new Random(); for(int i = 0; i < 10; i++) { Console.Write("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} ", r.NextDouble().ToString("0.0000"), r.NextDouble().ToString("0.0000"), r.NextDouble().ToString("0.0000"), r.NextDouble().ToString("0.0000"), r.NextDouble().ToString("0.0000"), r.NextDouble().ToString("0.0000"), r.NextDouble().ToString("0.0000"), r.NextDouble().ToString("0.0000"), r.NextDouble().ToString("0.0000"), r.NextDouble().ToString("0.0000")); ...

Get .NET Common Language Runtime Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.