The following demonstrates how to use Delphi language to download random data from a 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 values from AlphaRNG device when using Entropy Server for Windows.


//
//
// A sample Delphi program that demonstrates how to retrieve random bytes from
// AlphaRNG device using Entropy Server for Windows.
//
//

program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  SysUtils,
  Classes;

var
 EntropyServerStream: TFileStream;
 ByteCount: LongWord;
 RandomByteArray: array[0..4] of Byte;
 RequestByteArray: array[0..7] of Byte;

begin
  EntropyServerStream := TFileStream.Create('\\.\pipe\AlphaRNG', fmOpenReadWrite);
  try
    // How many random bytes to retrieve
    ByteCount := 5;


    // Prepare the entropy server request
    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(RandomByteArray, SizeOf(RandomByteArray));


  finally
    EntropyServerStream.Free;
  end;

  // Print all random bytes retrieved
  Writeln('random byte 0: ', RandomByteArray[0]);
  Writeln('random byte 1: ', RandomByteArray[1]);
  Writeln('random byte 2: ', RandomByteArray[2]);
  Writeln('random byte 3: ', RandomByteArray[3]);
  Writeln('random byte 4: ', RandomByteArray[4]);

end.