The following Delphi sample code downloads random data from a SwiftRNG device on Windows.
Before using the example, make sure your Delphi project targets the 32-bit Windows platform and the SwiftRNG device is plugged into an available USB port.
A thread-safe and process-safe 32-bit SwiftRNG.dll is included in the software kit.
Note: the following method is deprecated. Use the alternative method described in Delphi sample code for the Windows entropy server.
Sample source code for retrieving an array of bytes with the 32-bit SwiftRNG.dll
//
//
// A sample Delphi program that demonstrates how to retrieve random bytes from
// SwiftRNG device using 32 bit SwiftRNG.dll.
// Author: Zac
//
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
const
randomNumberCount = 50; // How many random bytes to retrieve
type
RandomBuffer = array [0 .. (randomNumberCount - 1)] of byte;
xbuffer = ^RandomBuffer;
var
i, z: integer;
zbuffer: randombuffer;
Function swftGetEntropySynchronized(ybuffer: xbuffer; y: longword): integer; stdcall; external 'C:\tools\windows-x86\SwiftRNG.dll';
begin
try
z := swftGetEntropySynchronized(@zbuffer, randomNumberCount);
writeln('status = ', z);
if z=0 then begin
for i:=0 to randomNumberCount-1 do
writeln('randombyte[',i,'] = ',zbuffer[i]);
end
else writeln('error occurred in SwftRNG');
readln;
except
on E: Exception do
writeln(E.ClassName, ': ', E.Message);
end;
end.