Speed of Random Numbers

lithium iodate whatdoiknow at doesntexist.net
Sat Aug 3 17:44:44 UTC 2019

On Saturday, 3 August 2019 at 16:35:34 UTC, Giovanni Di Maria 
> Do you know other faster functions or methods to generate 
> random numbers?
> For me the "goodness of random" is NOT important.
> Thank you very much
> GIovanni Di Maria

First off you could try to use a faster RNG engine than the 
default. The easiest way is to define a variable containing it 
and passing it to the functions each time.

auto rng = Xorshift(1234);
randomNumber = uniform!uint(rng);

This basic change approximately halved the 5 seconds your 
original example needs on my computer.
Another simple approach that I have tried is simply hashing the 
iterator using a fast hash function.
With xxHash32 I got the time down to 0.25 seconds. I also tried 
xxHash64 and FNV1a but they were not faster in my quick test.

More information about the Digitalmars-d-learn mailing list