Random Number Generator: Difference between revisions

m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
m (Bot: Replace deprecated source tag with syntaxhighlight)
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
Line 193:
Implementation according to Wikipedia:
 
<sourcesyntaxhighlight lang="c">
#include <stddef.h>
#include <stdint.h>
Line 268:
index++;
return y;
}</sourcesyntaxhighlight>
 
Some implementations automatically seed the generator with seed 5489, but this will (obviously) lead to the same outputs at every initialization.
Line 289:
If you are still not satisfied, you may want to build your own PRNG. You can do this in a fairly trial-and-error way by writing something that looks good and subjecting it to automated statistical testing suites such as [http://simul.iro.umontreal.ca/testu01/tu01.html TestU01]'s SmallCrush, Crush and finally BigCrush. These tests are very easy to run and can quickly point out problems, for example:
 
<sourcesyntaxhighlight lang="c">
#include <unif01.h>
#include <bbattery.h>
Line 307:
unif01_DeleteExternGenBits(gen);
}
</syntaxhighlight>
</source>
 
SmallCrush will report that this generator failed 12 out of 15 statistical tests. The other tests, which are also much slower, are therefore not necessary.