Home  |  Delphi .net Home  |  System.Random  |  Next Method
  
Next  
Method  
Gets the next random integer
Random Class
System NameSpace
CF1.  Function Next : Integer;
CF2.  Function Next ( UpperThreshold : Integer ) : Integer;
CF3.  Function Next ( LowerThreshold : Integer; UpperThreshold : Integer ) : Integer;
CF : Methods with this mark are Compact Framework Compatible
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
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
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.
   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.
   Value 1 = 8
   Value 2 = 6
   Value 3 = 1
   Value 4 = 2
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author