The following demonstrates how to use Delphi language for generating random numbers between 0 and 1 using the AlphaRNG-32.dll.
We recommend using the new AlphaRNG-32/64.dll which provides a simplified and flexible API for interracting with AlphaRNG Entropy Server.
Before using the following examples, make sure your Delphi project is targeted for Windows 32 bit platform,
the AlphaRNG device is plugged into one of USB ports available and the entropy-server.exe
is running on same system.
Both AlphaRNG-32.dll and AlphaRNG-64.dll are included in the AlphaRNG 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 AlphaRNG Entropy Server for Windows and AlphaRNG-32.dll
//
//
// A sample Delphi program that demonstrates how to generate random numbers
// between 0 and 1 with 10 decimals using AlphaRNG Entropy Server for Windows
// and AlphaRNG-32.dll
//
// For 64-bit Delphi applications use AlphaRNG-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\alrng-windows-binaries\windows-x86-vs-2019\AlphaRNG-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.