Jump to content
Tommi Prami

Good quality Random number generator implementation

Recommended Posts

Could someone point into nice implementation?

Would be nice (but not 100% necessary) that would have similar functionality than RTL version have. More than less drop in replacement (Easy to port)

 

-Tee-

Share this post


Link to post

What properties are you looking for. The reason that there are many different algorithms in use is that different applications have different requirements. 

Share this post


Link to post

For now, I am open to all suggestions 🙂 Just need to get random numbers and have some Randomize-functionality. 

As long it is way better tna build in RTL version. If can use it to replace RTL version in code, way or other, I am happy 🙂

 

-Tee-

Share this post


Link to post

I don't get this. If you don't have any particular needs, then I don't see how anybody can offer suggestions. And if all you want is a list of libraries, then websearch will get you that.

 

Do you know what you are going to do with these random numbers? 

Share this post


Link to post

Both XOrShift and ISAAC has nice Delphi implementations. They are both PRNGs but it you initialize them with the Random function, they will work quite well.

Share this post


Link to post
3 hours ago, David Heffernan said:

I don't get this. If you don't have any particular needs, then I don't see how anybody can offer suggestions. And if all you want is a list of libraries, then websearch will get you that.

 

Do you know what you are going to do with these random numbers? 

I just need random numbers that have better quality than stock Random() function in the RTL.

I think that is valid requirement.

 

-Tee-

Share this post


Link to post
35 minutes ago, Tommi Prami said:

I just need random numbers that have better quality than stock Random() function in the RTL.
I think that is valid requirement.

Yes it is, but if you can't define what "better quality" is then your request is meaningless.

 

In any case, like David said, a web search should give you plenty of candidates. Did you try that first?

  • Like 3

Share this post


Link to post

@KodeZwerg
That's not portable, though - and the quality of the PRNG would depend a lot on the parameters to BCryptOpenAlgorithmProvider.

Share this post


Link to post
7 hours ago, Tommi Prami said:

I just need random numbers that have better quality than stock Random() function in the RTL.

I think that is valid requirement.

 

-Tee-

What is the problem about the current one? What makes it "low quality"?

  • Like 2

Share this post


Link to post
program Project2;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils;

Const
 MAX_NUMBER = 1000;
 CYCLECOUNT = Integer.MaxValue;

Var
 numbers: Array[0.. MAX_NUMBER - 1] Of Integer;
 a, min, max: Integer;

begin
 Randomize;

 For a := Low(numbers) to High(numbers) Do
  numbers[a] := 0;

 For a := 1 To CYCLECOUNT Do
  Inc(numbers[Random(MAX_NUMBER)]);

 min := CYCLECOUNT;
 max := 0;

 For a := Low(numbers) To High(numbers) Do
  Begin
   If numbers[a] < min Then min := numbers[a]
     Else
   If numbers[a] > max Then max := numbers[a];
  End;

 WriteLn('After ' + CYCLECOUNT.ToString + ' cycle(s), minimum amount of occurrences of the same number is ' + min.ToString + ', maximum is ' + max.ToString);
 ReadLn;
end.


After 2147483647 cycle(s), minimum amount of occurrences of the same number is 2144157, maximum is 2150811

That means, the luckiest random number was hit 6654 times more than the least lucky one (from more than 2 billion attempts!).

 

Delphi's internal random number generator has a healthy dispersion. It's not perfect, but it is more than enough for average use.

Edited by aehimself

Share this post


Link to post
On 4/28/2021 at 10:28 AM, Tommi Prami said:

Could someone point into nice implementation?

Would be nice (but not 100% necessary) that would have similar functionality than RTL version have. More than less drop in replacement (Easy to port)

 

-Tee-

OK, it depends. Anyway, I suggest - xoshiro / xoroshiro generators

Or 🙂 start with simple SplitMix64

Efficiently Generating a Number in a Range

Edited by julkas

Share this post


Link to post
Guest

If you have €1800/yr you can go /n software (IpWorks + SecureBlackbox).

No sources 😞

Share this post


Link to post

OK,

 

Let me try again, any reasonably fast, Free and OpenSource implementation of good Random number generator algorithm, that is tested statistically to give better randomness than Stock RTL one.. 

I have no knowledge on which algorithm is best for what, that is why I am asking. I have an impression that Mersenne twisters are not suggested anymore. As mentioned above xoshiro / xoroshiro generators I have heard are good. But again, have no idea how to choose better one. I would not ask if I had all needed info 🙂

 

-Tee-

Edited by Tommi Prami

Share this post


Link to post
19 minutes ago, aehimself said:

Holy crap this is awesome! Imagine shrinking this to a hardware key 😄

Just as random, almost as cool, and has a slightly smaller risk of invoking a visit from Homeland Security: https://www.orau.org/ptp/collection/consumer products/dudice.htm

A dice made of depleted uranium 🙂

 

Anyway, it is possible to get USB-sized true randomness, just without the coolness factor. For example: https://www.amazon.com/TrueRNG-V3-Hardware-Random-Generator/dp/B01KR2JHTA/ref=pd_sbs_1

Share this post


Link to post
14 hours ago, Tommi Prami said:

OK,

 

Let me try again, any reasonably fast, Free and OpenSource implementation of good Random number generator algorithm, that is tested statistically to give better randomness than Stock RTL one.. 

I have no knowledge on which algorithm is best for what, that is why I am asking. I have an impression that Mersenne twisters are not suggested anymore. As mentioned above xoshiro / xoroshiro generators I have heard are good. But again, have no idea how to choose better one. I would not ask if I had all needed info 🙂

 

-Tee-

You have already had numerous suggestions that meet all your requirements. 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×