Mono Class Library: System.Random Overview | Members

System.Random Constructor

Constructs a new instance of the Random class using the specified seed value. [Edit]

public Random (int Seed)

Parameters

Seed
A int used as the starting value for the pseudo-random number sequence. [Edit]

Remarks

Note: To construct instances that produce different random number sequences, invoke this constructor using different seed values such as might be produced by the system clock. Note, however that on high performance systems, the system clock might not change between invocations of the constructor, in which case the seed value will be the same for different instances of Random . When this is the case, additional operations are required to have the seed values differ in each invocation.
[Edit]

Example

The following example demonstrates using a bitwise complement operation to obtain different random numbers using a time-dependent seed value on high performance systems.

C# Example
using System;
class RandomTest {
    public static void Main() {
        Random rand1 = new Random();
        Random rand2 = new Random(Environment.TickCount);
        Console.WriteLine("The random number is {0}",rand1.Next());
        Console.WriteLine("The random number is {0}",rand2.Next());

        Random rdm1 = new Random(unchecked(Environment.TickCount)); 
        Random rdm2 = new Random(~unchecked(Environment.TickCount)); 
        Console.WriteLine("The random number is {0}",rdm1.Next());
        Console.WriteLine("The random number is {0}",rdm2.Next());
    }
}
   
The output is
The random number is 1990211954
The random number is 1990211954
The random number is 1990211954
The random number is 964628126

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0