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"));
        Console.WriteLine();
    }
    for(int i = 0; i < 10; i++)
    {
        Console.Write("{0}  {1}  {2}  {3}  {4}  {5}  {6}  {7}  {8}  {9} ",
            r.Next(0,99).ToString("00"),
            r.Next(0,99).ToString("00"),
            r.Next(0,99).ToString("00"),
            r.Next(0,99).ToString("00"),
            r.Next(0,99).ToString("00"),
            r.Next(0,99).ToString("00"),
            r.Next(0,99).ToString("00"),
            r.Next(0,99).ToString("00"),
            r.Next(0,99).ToString("00"),
            r.Next(0,99).ToString("00"));
        Console.WriteLine();
    }
}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.79.59