The following example shows how to use Delphi to generate random numbers between 0 and 1 using AlphaRNG-32.dll. We recommend using AlphaRNG-32.dll or AlphaRNG-64.dll, which provide a simple and flexible API for interacting with the AlphaRNG Entropy Server. Before using the example, make sure your Delphi project targets 32-bit Windows, the AlphaRNG device is plugged into an available USB port, and entropy-server.exe is running on the same system. Both AlphaRNG-32.dll and AlphaRNG-64.dll are included in the AlphaRNG software kit, which can be downloaded from the latest release on GitHub.

Generating 10 random numbers between 0 and 1 with 10 decimals through 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.