25,161
edits
Changes
no edit summary
PRNGs maintain a state variable, a bitwise superset of the random number, initialized by a [https://en.wikipedia.org/wiki/Random_seed random seed] - a constant for the same sequence each time, i.e. for Zobrist keys, otherwise, something like [https://en.wikipedia.org/wiki/System_time system time] to produce varying pseudo randoms. Each call of the PRNG routine performs certain operations or [[Bit-Twiddling|bit-twiddling]] on that state, leaving the next pseudo random number. For various applications more or less important features are [https://en.wikipedia.org/wiki/Randomness randomness], resolution, ([https://en.wikipedia.org/wiki/Equidistributed_sequence uniform]) [https://en.wikipedia.org/wiki/Probability_distribution distribution], and [https://en.wikipedia.org/wiki/Periodicity periodicity] - topic of various [https://en.wikipedia.org/wiki/Randomness_tests randomness tests] - and further performance, and [https://en.wikipedia.org/wiki/Software_portability portability].
==LCG==A common method used in many library functions, such as [[Zobrist HashingC]]/[[Cpp|Zobrist hashingC++]]rand() is the [https://en.wikipedia.org/wiki/Linear_congruential_generator linear congruential generator] with about 12*64 keys has less issues with randomness and period(LCG) based on multiply, but with distributionadd, and requires [https://en.wikipedia.org/wiki/Linear_independence linear independenceModulo_operation modulo] so that a small subset with integers, where some past implementations had serious shortcomings in the randomness, distribution and period of the sequence <ref>"In the past, some implementations of rand() have had serious shortcomings in the randomness, distribution and period of all keys doesn't xor to zero. Despite selected hardthe sequence produced (in one well-known example, the low-coded order bit simply alternated between 1 and 0 between calls) rand() is not recommended for serious random constants used at compile time-number generation needs, many programs like cryptography. It is recommended to use an own PRNG based on C++11's random number generation facilities to replace rand()." [httpshttp://en.wikipediacppreference.orgcom/w/cpp/numeric/wikirandom/Recurrence_relation recurrence relationrand rand - cppreference.com] </ref>. Due to such issues in rand() implementations, where lower bits are less random than higher bits, it is recommended not to use [https://en.wikipedia.org/wiki/GF%282%29 GFModulo_operation modulo] X to reduce the integer range from RAND_MAX to X, but division by (2RAND_MAX div X)] such as <ref>[https://enwww.wikipediastmintz.orgcom/ccc/wikiindex.php?id=88293 Re: random book moves/Mersenne_twister Mersenne Twisterrandom generator] by [[Thorsten Greiner]], [[CCC]] , January 13, 2000</ref> - or to use C++11's random number generation facilities to replace rand <ref>[httpshttp://en.wikipediacppreference.orgcom/w/cpp/wikinumeric/Xorshift Xorshiftrandom Pseudo-random number generation - cppreference.com]</ref>. ==RKISS==[[Stockfish]] (since 2.0) uses an implementation by [[Heinz van Saanen]] based on [[Bob Jenkins|Bob Jenkins']] [[Bob Jenkins#RKISS|RKISS]], a member of [[Mathematician#GMarsaglia|George Marsaglia's]] Xorshift familly. ==RANROT B3==[[Amy]] by [[Thorsten Greiner]] <ref>amy-0.8.7.tar.gz /src/random.c</ref> uses an implementation of Agner Fog's RANROT B3 <ref>[http://www.agner.org/ Agner Fog] ('''2001'''). ''Chaotic Random Number Generators with Random Cycle Lengths''. [http://www.agner.org/random/theory/chaosran.pdf pdf]</ref>, also recommended by [[Stefan Meyer-Kahlen]] as used in [[Shredder]] <ref>[https://www.stmintz.com/ccc/index.php?id=88309 Re: random book moves/ random generator] by [[Stefan Meyer-Kahlen]], [[CCC]], January 13, 2000</ref>. ==MT==[[Arasan]] 20.x switched to C++11 random number support using [https://en.wikipedia.org/wiki/Mersenne_twister Mersenne Twister] std::mt19937_64 <ref>[https://github.com/jdart1/arasan-chess/blob/master/src/movegen.h arasan-chess/movegen.h at master · jdart1/arasan-chess · GitHub]</ref> <ref>[http://www.cplusplus.com/reference/random/mt19937_64/ mt19937_64 - C++ Reference]</ref>. ==ChaCha==The [[Rust]] engine [[Asymptote]] uses the [https://en.wikipedia.org/wiki/Salsa20#ChaCha_variant ChaCha] [https://en.wikipedia.org/wiki/Stream_cipher stream cipher] developed by [[Mathematician#DJBernstein|Daniel J. Bernstein]], built on a [https://en.wikipedia.org/wiki/Pseudorandom_function_family pseudorandom function] based on [https://en.wikipedia.org/wiki/Salsa20#ChaCha_variant add-rotate-xor (ARX)] operations <ref>[https://doc.rust-lang.org/1.0.0/rand/chacha/struct.ChaChaRng.html rand::chacha::ChaChaRng - Rust]</ref>.
=Applications=
* [http://www.stat.tugraz.at/stadl/random.html Random Number Generation] by [[Mathematician#EStadlober|Ernst Stadlober]]
* [http://www.paulm.org/random.html Random Number Generators]
* [https://en.wikipedia.org/wiki/Salsa20 Salsa20 from Wikipedia]
==Language Support==
===[[Basic]]===