Example of the Random class constructors and Random.NextDouble( ) method.
using System;
using System.Threading;
public class RandomObjectDemo
{
static void RunIntNDoubleRandoms( Random randObj )
{
for( int j = 0; j < 6; j++ )
Console.Write( " {0,10} ", randObj.Next( ) );
for( int j = 0; j < 6; j++ )
Console.Write( " {0:F8} ", randObj.NextDouble( ) );
}
static void FixedSeedRandoms( int seed )
{
Console.WriteLine( "seed = {0}:", seed );
Random fixRand = new Random( seed );
RunIntNDoubleRandoms( fixRand );
}
static void AutoSeedRandoms( )
{
RunIntNDoubleRandoms( new Random( ) );
}
static void Main( )
{
FixedSeedRandoms( 456 );
AutoSeedRandoms( );
}
}
Related examples in the same category