O'Reilly logo

.NET Common Language Runtime Unleashed by Kevin Burton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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")); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required