The following demonstrates how to use Delphi language to download random positive real numbers within a range from an AlphaRNG device when used with Entropy Server for Windows. The following code will only work when running AlphaRNG Entropy Server. Before using the following example, make sure the AlphaRNG device is plugged into one of USB ports available and entropy-server.exe is running on same system.

A Delphi sample source code for retrieving random positive real values within a range from an AlphaRNG device when using Entropy Server for Windows.



//
//
// A sample Delphi program that demonstrates how to retrieve random real numbers
// within a [10.5 ... 11.6] range from AlphaRNG device using Entropy Server for Windows.
//
//

program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  SysUtils,
  Classes;

var
 EntropyServerStream: TFileStream;
 ByteCount: LongWord;
 DwnldRndNumber: Uint32;
 DwnldRealNumber: Real48;
 FinalRandNumber: Real48;
 MinRandomValue: Real48;
 MaxRandomValue: Real48;
 TmpRealNumber: Real48;
 RequestByteArray: array[0..7] of Byte;

begin
  EntropyServerStream := TFileStream.Create('\\.\pipe\AlphaRNG', fmOpenReadWrite);
  try

    // Set the random expected range
    MinRandomValue := 10.5;
    MaxRandomValue := 11.6;

    // How many random bytes to retrieve
    ByteCount := SizeOf(DwnldRndNumber);

    // Prepare the entropy server request
    // For more information visit https://tectrolabs.com/docs/alpharng/entropy-server-api/
    Move(ByteCount, RequestByteArray[4], SizeOf(ByteCount));

    // Send request to the entropy server.
    // Request bytes should be sent at once with no delay in between.
    EntropyServerStream.WriteBuffer(RequestByteArray, SizeOf(RequestByteArray));

    // Retrieve random bytes from the entropy server.
    // Random bytes should be received at once with no delay in between.
    EntropyServerStream.ReadBuffer(DwnldRndNumber, SizeOf(DwnldRndNumber));

    // Adjust to the expected range
    DwnldRealNumber := DwnldRndNumber;
    FinalRandNumber := (DwnldRealNumber / 4294967295) * (MaxRandomValue - MinRandomValue) + MinRandomValue;

  finally
    EntropyServerStream.Free;
  end;

  // Print the final random value
  Writeln('random real: ', FinalRandNumber:2:4);

end.

A Delphi sample source code for retrieving random positive real values within a range from an AlphaRNG device when using using AlphaRNG-32.dll


//
//
// A sample Delphi program that demonstrates how to retrieve random real numbers
// within a [10.5 ... 11.6] range from AlphaRNG device using using AlphaRNG-32.dll
//
//

program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  SysUtils,
  Classes;

type
  DwnldRndNumberType = Uint32;
  xDwnldRndNumberType = ^DwnldRndNumberType;

var
 EntropyServerStream: TFileStream;
 DwnldRndNumber: DwnldRndNumberType;
 PDwnldRndNumber:  ^Uint32;
 DwnldRealNumber: Real48;
 FinalRandNumber: Real48;
 MinRandomValue: Real48;
 MaxRandomValue: Real48;
 TmpRealNumber: Real48;
 Status: Integer;

 Function getEntropy(p: xDwnldRndNumberType; y: longword): integer; stdcall; external 'C:\tools\alrng-windows-binaries\windows-x86-vs-2019\AlphaRNG-32.dll';


begin
  EntropyServerStream := TFileStream.Create('\\.\pipe\AlphaRNG', fmOpenReadWrite);
  try

    // Set the random expected range
    MinRandomValue := 10.5;
    MaxRandomValue := 11.6;

    Status := getEntropy(@DwnldRndNumber, SizeOf(DwnldRndNumber));
    if Status = 0 then
      begin
        // Adjust to the expected range
        DwnldRealNumber := DwnldRndNumber;
        FinalRandNumber := (DwnldRealNumber / 4294967295) * (MaxRandomValue - MinRandomValue) + MinRandomValue;

        // Print the final random value
        Writeln('random real: ', FinalRandNumber:2:4);

      end
      else
       Writeln('status in error: ', Status);


  finally
    EntropyServerStream.Free;
  end;


end.