Speed of Random Numbers
Giovanni Di Maria
calimero22 at yahoo.it
Sat Aug 3 16:35:34 UTC 2019
Hi to everybody
I am doing some experiments about random numbers.
I need "extreme speed" for the generation for numbers from 1 to 8.
Generating 500_000_000 numbers with this code:
-----------------------------
import std.stdio, std.array, std.random;
void main()
{
byte c;
writeln("Start");
for(int k=1;k<=500_000_000;k++)
c=uniform!ubyte() % 8 +1; //<<< ======= RANDOM
writeln("Stop");
}
-----------------------------
I get these results:
c=uniform!ubyte() % 8 +1; ======>>> Execution time: 15.563 s
c=cast(byte)uniform(1, 9); ======>>> Execution time: 24.218 s
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
More information about the Digitalmars-d-learn
mailing list