unit SysRandom;
interface
  procedure Randomize;
implementation
{$ifdef UNIX}
  procedure Randomize;
  const
    RandomDeviceName = '/dev/urandom';
  var
    RandomNumber: Cardinal;
    RandomReader: File of Cardinal;
  begin
    Assign(RandomReader, RandomDeviceName);
    {$push}
    {turn off runtime error gen}
    {$IOChecks off}
    Reset(RandomReader);

    if IOResult() = 0 then
    begin
      Read(RandomReader, RandomNumber);

      if IOResult() = 0 then
      begin
        System.RandSeed := RandomNumber;
        Close(RandomReader);
      end
      else System.Randomize;
    end
    {$pop}
    else
    begin
      System.Randomize;
    end;
  end;
{$else}
  procedure Randomize;
  begin
    System.Randomize;
  end;
{$endif}
end.