Go to file
R. Eric Wheeler d0ee467262 Renegade -> Olive BBS 2020-05-18 17:40:57 -07:00
tests Added LinuxRandom class, seperate URandom class 2016-05-07 10:02:44 -07:00
.gitignore first commit 2016-05-04 10:28:06 -07:00
LICENSE first commit 2016-05-04 10:28:06 -07:00
Olive.Random.BSDRandom.pas Renegade -> Olive BBS 2020-05-18 17:40:57 -07:00
Olive.Random.Generic.pas Renegade -> Olive BBS 2020-05-18 17:40:57 -07:00
Olive.Random.LinuxRandom.pas Renegade -> Olive BBS 2020-05-18 17:40:57 -07:00
Olive.Random.RandomInterface.pas Renegade -> Olive BBS 2020-05-18 17:40:57 -07:00
Olive.Random.URandom.pas Renegade -> Olive BBS 2020-05-18 17:40:57 -07:00
Olive.Random.WinRandom.pas Renegade -> Olive BBS 2020-05-18 17:40:57 -07:00
Olive.Random.pas Renegade -> Olive BBS 2020-05-18 17:40:57 -07:00
README.md Update README.md 2020-05-13 16:29:24 +00:00

README.md

Free Pascal Random Bytes

This file is a part of Olive BBS.

This will only work with Free Pascal version 3+.

Usage

Make sure to include {$mode objfpc}{$H+} in your header or compile with -S2 -Sh switches.

Program RandomTest;
{$mode objfpc}{$H+}

uses
  Olive.Random,
  Classes;

var
  R : TRandom;
  S : AnsiString;
  T : TBytes;
begin
  R := TRandom.Init;
  S := R.GetString(22);
  T := R.GetBytes(22);
  R.Free;

You can also use a custom random generator. It needs to implement Olive.Random.RandomInterface;

Program RandomTest;
{$mode objfpc}{$H+}

uses
  Olive.Random,
  MyCustomGenerator,
  Classes;

var
  R : TRandom;
  S : AnsiString;
  T : TBytes;
begin
  R := TRandom.Init;
  R.RandomGenerator := MyCustomGenerator.Create;
  S := R.GetString(22);
  T := R.GetBytes(22);
  R.SetDefaultGenerator; // To get back to the default Generator.
  S := R.GetString(22);
  T := R.GetBytes(22);
  R.Free;
  • On Linux systems TRandom uses SYS_getrandom.
  • On Windows systems TRandom uses Windows built in CryptGenRandom function.
  • On BSD systems TRandom uses arc4random_buf this is the same on Mac systems, because Mac = FreeBSD).

TRandom will fall back on reading from /dev/urandom, then /dev/random, and finally Free Pascal's Random function which uses the Mersenne Twister algorithm to get random bytes.