From d9678a626025a1e637d64536eef8d53b4d1cd0e1 Mon Sep 17 00:00:00 2001 From: sikofitt Date: Wed, 4 May 2016 14:34:19 -0700 Subject: [PATCH] Added GetSystemBytes for BSD Unit --- Renegade.Random.BSDRandom.pas | 13 ++++++++++++- Renegade.Random.Generic.pas | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Renegade.Random.BSDRandom.pas b/Renegade.Random.BSDRandom.pas index 339f4bd..b99ebd0 100644 --- a/Renegade.Random.BSDRandom.pas +++ b/Renegade.Random.BSDRandom.pas @@ -57,11 +57,22 @@ type function GetString(NBytes : SizeUInt) : AnsiString; end; -procedure arc4random_buf(var Buffer : PCChar; StringLength : SizeInt); +procedure arc4random_buf(var Buffer : PCChar; StringLength : CInt); cdecl;varargs;external 'c' name 'arc4random_buf'; implementation +function GetSystemBytes(var RandomByteBuffer : TBytes; NBytes : SizeUint) : CInt; +begin + arc4random_buf(@RandomByteBuffer^, NBytes); + if Length(RandomByteBuffer^) <> NBytes then + begin + Result := -1; + end else + begin + Result := Length(RandomByteBuffer^); + end; +end; function BSDRandom.GetBytes(NBytes : SizeUInt) : TBytes; var diff --git a/Renegade.Random.Generic.pas b/Renegade.Random.Generic.pas index 7ae9292..668d792 100644 --- a/Renegade.Random.Generic.pas +++ b/Renegade.Random.Generic.pas @@ -13,7 +13,7 @@ { Foundation, either version 3 of the License, or } { (at your option) any later version. } { } -{ Renegade is distributed in the hope that it will be } +{ Renegade is distributed in the hope that it will be } { useful, but WITHOUT ANY WARRANTY; without even the } { implied warranty of MERCHANTABILITY or FITNESS FOR } { A PARTICULAR PURPOSE. See the GNU General Public }