The following demonstrates how to use Delphi language for generating random numbers between 0 and 1 using the SwiftRNG-32.dll.
We recommend using the new SwiftRNG-32/64.dll which provides a simplified and flexible API for interracting with SwiftRNG Entropy Server.
Before using the following examples, make sure your Delphi project is targeted for Windows 32 bit platform,
the SwiftRNG device is plugged into one of USB ports available and Entropy Server
is running on same system.
Both SwiftRNG-32.dll and SwiftRNG-64.dll are included in the SwiftRNG software kit and can be downloaded from this location.
A sample Delphi program that demonstrates how to generate 10 random numbers between 0 and 1 with 10 decimals using SwiftRNG Entropy Server for Windows and SwiftRNG-32.dll
//
//
// A sample Delphi program that demonstrates how to generate random numbers
// between 0 and 1 with 10 decimals using SwiftRNG Entropy Server for Windows
// and SwiftRNG-32.dll
//
// For 64-bit Delphi applications use SwiftRNG-64.dll
//
//
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
const
randomNumberCount = sizeof(UInt64); // How many random bytes to retrieve
type
RandomBuffer = array [0 .. randomNumberCount-1] of byte;
xbuffer = ^RandomBuffer;
var
i, status: integer;
zbuffer: randombuffer;
randUInt64: UInt64;
randDouble: Double;
Function getEntropy(x: xbuffer; y: longword): integer; stdcall; external 'C:\tools\windows-binaries\windows-x86\SwiftRNG-32.dll';
begin
try
writeln('Generating 10 random numbers between 0 and 1 with 10 decimals');
for i:=0 to 9 do
begin
status := getEntropy(@zbuffer, randomNumberCount);
if status = 0 then
begin
Move (zbuffer, randUInt64, randomNumberCount);
randDouble := randUInt64 mod 9999999999;
randDouble := randDouble / 10000000000.0;
writeln('random number is: ', randDouble:12:10);
end
else
begin
writeln('Could not retrieve entropy, is entropy server running?');
break;
end;
end
except
on E: Exception do
writeln(E.ClassName, ': ', E.Message);
end;
end.