Returns a nonnegative random number less than the specified maximum.
using System;
public class RandomNextDemo
{
static void NoBoundsRandoms( int seed )
{
Random randObj = new Random( seed );
for( int j = 0; j < 6; j++ )
Console.WriteLine( randObj.Next( ) );
}
static void UpperBoundRandoms( int seed, int upper )
{
Random randObj = new Random( seed );
// Generate six random integers from 0 to the upper bound.
for( int j = 0; j < 6; j++ )
Console.WriteLine( randObj.Next( upper ) );
}
static void BothBoundsRandoms( int seed, int lower, int upper )
{
Random randObj = new Random( seed );
// Generate six random integers from the lower to upper bounds.
for( int j = 0; j < 6; j++ )
Console.WriteLine( randObj.Next( lower, upper) );
}
static void Main( )
{
NoBoundsRandoms( 234 );
UpperBoundRandoms( 234, 200000);
BothBoundsRandoms( 234, -2, 2);
}
}
Related examples in the same category