Get a nonnegative random integer that is less than the specified maximum in CSharp
Description
The following code shows how to get a nonnegative random integer that is less than the specified maximum.
Example
/*from w ww . j ava 2 s .c o m*/
using System;
public class RandomNextDemo
{
static void Main( )
{
Random randObj = new Random( 1 );
// Generate six random integers from 0 to the upper bound.
for( int j = 0; j < 6; j++ )
Console.Write( "{0,11} ", randObj.Next( 2 ) );
}
}
The code above generates the following result.