Skip to content

Commit

Permalink
Renamed units, FPC does namespaces, but is confused by namespaces mor…
Browse files Browse the repository at this point in the history
…e than 1 dot., Updated readme
  • Loading branch information
sikofitt committed Feb 23, 2017
1 parent 4e23838 commit e3545fd
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 27 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ begin
R.Free;
```

You can also use a custom random generator. It needs to implement Renegade.Random.RandomInterface;
You can also use a custom random generator. It needs to implement Random.RandomInterface;
```pascal
Program RandomTest;
{$mode objfpc}{$H+}
Expand All @@ -56,8 +56,8 @@ begin
```


* On Linux systems TRandom reads from /dev/urandom.
* On Linux systems TRandom trys to use syscall(SYS_getrandom) if that fails it reads from /dev/urandom and then /dev/random before failing.
* On Windows systems TRandom uses Windows built in [CryptGenRandom](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379942(v=vs.85).aspx "CryptGenRandom") function.
* On BSD systems TRandom reads from /dev/urandom. (TODO : read from [arc4random_buf](https://www.freebsd.org/cgi/man.cgi?query=arc4random_buf&sektion=3 "arc4random_buf") this is the same on Mac systems, because Mac = FreeBSD)
* On BSD systems TRandom uses arc4random_buf. (Done : read from [arc4random_buf](https://www.freebsd.org/cgi/man.cgi?query=arc4random_buf&sektion=3 "arc4random_buf") this is the same on Mac systems, because Mac = FreeBSD)

TRandom will fall back on Free Pascal's [Random](http://www.freepascal.org/docs-html/rtl/system/random.html "Random") function which uses the [Mersenne Twister](https://en.wikipedia.org/wiki/Mersenne_Twister "Mersenne Twister") algorithm to get random bytes.
9 changes: 5 additions & 4 deletions Renegade.Random.BSDRandom.pas → Random.BSDRandom.pas
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
{ `--- ---' }
{*******************************************************}

{ ???: Todo - use arc4random_buf }
{$mode objfpc}{$H+}
Unit Renegade.Random.BSDRandom;
{$codepage utf-8}
{namespace Renegade.Random }
Unit Random.BSDRandom;

interface

Expand All @@ -44,8 +45,8 @@ interface
Objects,
Classes,
SysUtils,
Renegade.Random.RandomInterface,
Renegade.Random.URandom;
Random.RandomInterface,
Random.URandom;

type
PCChar = ^CChar;
Expand Down
5 changes: 3 additions & 2 deletions Renegade.Random.Generic.pas → Random.Generic.pas
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@
{*******************************************************}

{$mode objfpc}{$H+}
Unit Renegade.Random.Generic;
{ namespace Renegade.Random }
Unit Random.Generic;

interface

uses
Objects,
Classes,
SysUtils,
Renegade.Random.RandomInterface;
Random.RandomInterface;

type
PRandomGeneric = ^RandomGeneric;
Expand Down
7 changes: 4 additions & 3 deletions Renegade.Random.LinuxRandom.pas → Random.LinuxRandom.pas
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
{*******************************************************}

{$mode objfpc}{$H+}
Unit Renegade.Random.LinuxRandom;
{ namespace Renegade.Random }
Unit Random.LinuxRandom;

interface

Expand All @@ -43,7 +44,7 @@ interface
Objects,
Classes,
SysUtils,
Renegade.Random.RandomInterface;
Random.RandomInterface;

const
{$IF DEFINED(CPU64)} SYS_getrandom = 318;
Expand Down Expand Up @@ -113,7 +114,7 @@ function LinuxRandom.GetString(NBytes : SizeUInt) : AnsiString;
end;
Buffer.Free;
end
else if (not FileExists('/dev/udrandom')) then
else if (not FileExists('/dev/urandom')) then
begin
Writeln('Random');
RandomByteBuffer := MTRandomBytes((NBytes*2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
{$mode objfpc}{$H+}
{$interfaces corba}
{$codepage UTF8}
Unit Renegade.Random.RandomInterface;

Unit Random.RandomInterface;

interface

Expand Down Expand Up @@ -74,11 +75,11 @@ function RandomTrait.MTRandomBytes(NBytes : SizeUInt) : TBytes;
var
i : SizeUint;
begin
Randomize;
System.Randomize;
SetLength(Result, (NBytes*2));
for i := 0 to (NBytes*2) do
begin
Result[i] := Random(MaxInt) mod 256;
Result[i] := System.Random(MaxInt) mod 256;
end;
SetLength(Result, NBytes);
end;
Expand Down
7 changes: 4 additions & 3 deletions Renegade.Random.URandom.pas → Random.URandom.pas
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
{*******************************************************}

{$mode objfpc}{$H+}
Unit Renegade.Random.URandom;
{ namespace Renegade.Random }
Unit Random.URandom;

interface

Expand All @@ -43,7 +44,7 @@ interface
Objects,
Classes,
SysUtils,
Renegade.Random.RandomInterface;
Random.RandomInterface;

const
{$IF DEFINED(CPU64)} SYS_getrandom = 318;
Expand Down Expand Up @@ -113,7 +114,7 @@ function URandom.GetString(NBytes : SizeUInt) : AnsiString;
end;
Buffer.Free;
end
else if (not FileExists('/dev/udrandom')) then
else if (not FileExists('/dev/urandom')) then
begin
Writeln('Random');
RandomByteBuffer := MTRandomBytes((NBytes*2));
Expand Down
5 changes: 3 additions & 2 deletions Renegade.Random.WinRandom.pas → Random.WinRandom.pas
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
{*******************************************************}

{$mode objfpc}{$H+}
Unit Renegade.Random.WinRandom;
{ namespace Renegade.Random }
Unit Random.WinRandom;

interface

Expand All @@ -43,7 +44,7 @@ interface
Classes,
SysUtils,
Windows,
Renegade.Random.RandomInterface;
Random.RandomInterface;

const
CRYPT_VERIFYCONTEXT = $F0000000;
Expand Down
12 changes: 7 additions & 5 deletions Renegade.Random.pas
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

{$mode objfpc}{$H+}
{$interfaces corba}
{$codepage utf-8}
{ namespace Renegade.Random }
Unit Renegade.Random;

interface
Expand All @@ -43,15 +45,15 @@ interface
Objects,
Classes,
SysUtils,
Renegade.Random.RandomInterface,
Random.RandomInterface,
{$IF DEFINED(LINUX)}
Renegade.Random.LinuxRandom
Random.LinuxRandom
{$ELSEIF DEFINED(WINDOWS)}
Renegade.Random.WinRandom
Random.WinRandom
{$ELSEIF DEFINED(BSD)}
Renegade.Random.BSDRandom
Random.BSDRandom
{$ELSE}
Renegade.Random.Generic;
Random.Generic;
{$ENDIF}
;

Expand Down
4 changes: 2 additions & 2 deletions tests/RandomTest.pas
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

Uses
Renegade.Random,
Renegade.Random.Generic,
Renegade.Random.RandomInterface,
Random.Generic,
Random.RandomInterface,
Classes,
SysUtils;

Expand Down

0 comments on commit e3545fd

Please sign in to comment.