Constructs a new instance of the Random class using the specified
seed value.
[Edit]
Parameters
- Seed
- A int used as the starting value for the pseudo-random number sequence.
[Edit]
Remarks
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