Home  |  Delphi .net Home  |  System.Random  |  NextDouble Method
NextDouble  
Method  
Gets the next random floating point number
Random Class
System NameSpace
CF1.  Function NextDouble ( ) : Double;
CF : Methods with this mark are Compact Framework Compatible
Description
Gets the next positive floating point random number in the range 0.0 up to, but not including 1.0
Microsoft MSDN Links
System
System.Random
 
 
Illustrating default and specified seeds
program Project1;
{$APPTYPE CONSOLE}

var
  rand  : System.Random;
  value : Double;
begin
  Console.WriteLine('Using the default seed values start unpredictably :');
  Console.WriteLine;

  rand  := System.Random.Create;
  value := rand.NextDouble;
  Console.WriteLine('Value 1 = {0}', value.ToString);
  value := rand.NextDouble;
  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.NextDouble;
  Console.WriteLine('Value 1 = {0}', value.ToString);
  value := rand.NextDouble;
  Console.WriteLine('Value 2 = {0}', value.ToString);

  Console.ReadLine;
end.
Show full unit code
  Using the default seed values start unpredictably :
  
  Value 1 = 0.449218966741682
  Value 2 = 0.201625648048532
  
  Using 123 as the seed always produces these values :
  
  Value 1 = 0.984556915231308
  Value 2 = 0.907815323168326
  
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author