The following demonstrates how to use Delphi language to download random data from a SwiftRNG device when used with Entropy Server for Windows. The following code will only work when running SwiftRNG Entropy Server. This is the recommended way for achieving maximum concurrent speed and performance. Before using the following example, make sure the SwiftRNG 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 SwiftRNG device when using Entropy Server for Windows.


//
//
// A sample Delphi program that demonstrates how to retrieve random bytes from
// SwiftRNG 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\SwiftRNG', 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.