Description |
Gets the next positive integer random number.
The numer is in the range 0 to 4,294,967,294 (inclusive) unless the optional LowerThreshold and UpperThreshold limits are specified. In this case, the UpperThreshold is 1 higher than the maximum possible returned value.
|
|
Microsoft MSDN Links |
System
System.Random
|
|
|
Illustrating default and specified seeds |
program Project1;
{$APPTYPE CONSOLE}
var
rand : System.Random;
value : Integer;
begin
Console.WriteLine('Using the default seed values start unpredictably :');
Console.WriteLine;
rand := System.Random.Create;
value := rand.Next;
Console.WriteLine('Value 1 = {0}', value.ToString);
value := rand.Next;
Console.WriteLine('Value 2 = {0}', value.ToString);
Console.WriteLine;
Console.WriteLine('Using 123 as the seed always produces these values :');
Console.WriteLine;
rand := System.Random.Create(123);
value := rand.Next;
Console.WriteLine('Value 1 = {0}', value.ToString);
value := rand.Next;
Console.WriteLine('Value 2 = {0}', value.ToString);
Console.ReadLine;
end.
| Show full unit code | Using the default seed values start unpredictably :
Value 1 = 1744524198
Value 2 = 1089714093
Using 123 as the seed always produces these values :
Value 1 = 2114319875
Value 2 = 1949518561
| | Illustrating range specifications | program Project1;
{$APPTYPE CONSOLE}
var
rand : System.Random;
value : Integer;
begin
rand := System.Random.Create;
value := rand.Next(5, 10);
Console.WriteLine('Value 1 = {0}', value.ToString);
value := rand.Next(5, 10);
Console.WriteLine('Value 2 = {0}', value.ToString);
value := rand.Next(1, 5);
Console.WriteLine('Value 3 = {0}', value.ToString);
value := rand.Next(1, 5);
Console.WriteLine('Value 4 = {0}', value.ToString);
Console.ReadLine;
end.
| Show full unit code | Value 1 = 8
Value 2 = 6
Value 3 = 1
Value 4 = 2
|
|
|
|