As of version 6, Random[]
was superseded by RandomReal[ ]
etc, but both still work perfectly well. Playing with some timing comparisons, I noticed that the original Random[]
function appears to be faster, in single repeated drawings ...
ALSO, using the syntax RandomReal[]
is faster than using RandomReal[{0,1}]
...
Table[RandomReal[{0,1}], {10^8}]; // AbsoluteTiming
Table[RandomReal[], {10^8}]; // AbsoluteTiming
Table[Random[], {10^8}]; // AbsoluteTiming
{10.1703,Null}
{7.00452, Null}
{4.99067, Null}
Similarly:
Do[RandomReal[{0, 1}], {10^7}]; // AbsoluteTiming
Do[RandomReal[], {10^7}]; // AbsoluteTiming
Do[Random[], {10^7}]; // AbsoluteTiming
{2.89869,Null}
{2.56348, Null}
{1.23561, Null}
Am I losing anything by not using the newer version, for basic Uniform(0,1) random draws like this?
EDIT: just to clarify ... the above refers to single calls on RandomReal
/ Random
: in my application, I am not able to call $10^7$ drawings in advance.
RandomReal
when generating multiple random numbers. How does the timing withRandom
compare withRandomReal[{0, 1}, 10^8]
? $\endgroup$Random
uses an older and poorer PRNG algorithm. Let me see if I can find some references. $\endgroup$Random
(and of the new ones available toRandomReal
) can be found in this tutorial: Random Number Generation under the "Legacy" entry. $\endgroup$Random
is using a weaker pseudoRNG under the hood. It's a linear congruential generator due to Marsaglia and Zaman if I recall correctly. Very good in its day, and fast. But it does suffer on certain types of correlation and lattice tests. As for internet references, there may be notes on MathGroup about this. $\endgroup$