Get a nonnegative random integer in CSharp

Description

The following code shows how to get a nonnegative random integer.

Example


using System;/*from   w  w w . j  a v  a2 s .co  m*/

public class RandomNextDemo  
{
    static void Main( )
    {  
        Random randObj = new Random( 1 );

        // Generate six random integers from 0 to int.MaxValue. 
        for( int j = 0; j < 6; j++ )
            Console.WriteLine( randObj.Next( ) );
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Development »




Console
Encoding
Environment
Random