Changes

Jump to: navigation, search

Pseudorandom Number Generator

2,711 bytes added, 18:52, 30 June 2021
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].
A common method used in many library functions, such as [[C]]/[[CppZobrist Hashing|C++Zobrist hashing]] rand() is the with about 12*64 keys has less issues with randomness and period, but with distribution, and requires [https://en.wikipedia.org/wiki/Linear_congruential_generator Linear_independence linear congruential generatorindependence] so that a small subset of all keys doesn't xor to zero. Despite selected hard-coded random constants used at compile time, many programs use an own PRNG based on multiply, add, [https://en.wikipedia.org/wiki/Modulo_operation moduloRecurrence_relation recurrence relation] 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 the sequence produced (in one well-known example, the low-order bit simply alternated between 1 and 0 between calls) rand() is not recommended for serious random-number generation needs, like cryptography. It is recommended to use C++11's random number generation facilities to replace rand()." [httphttps://en.cppreferencewikipedia.comorg/wwiki/cpp/numeric/random/rand rand - cppreference.comGF%282%29 GF(2)]</ref>. Due to such issues in rand() implementations, where lower bits are less random than higher bits, it is recommended not to use as [https://en.wikipedia.org/wiki/Modulo_operation moduloMersenne_twister Mersenne Twister] X to reduce the integer range from RAND_MAX to X, but division by (RAND_MAX div X) <ref>or [https://www.stmintz.com/ccc/index.php?id=88293 Re: random book moves/ random generator] by [[Thorsten Greiner]], [[CCC]], January 13, 2000</ref> - or to use C++11's random number generation facilities to replace rand <ref>[http://en.cppreferencewikipedia.comorg/wwiki/cpp/numeric/random Pseudo-random number generation - cppreference.comXorshift Xorshift]</ref>.
==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=
* [[Mathematician#KEntacher|Karl Entacher]] ('''2000'''). ''[http://random.mat.sbg.ac.at/results/karl/server/server.html A collection of classical pseudorandom number generators with linear structures - advanced version]''.
* [http://www.agner.org/ Agner Fog] ('''2001'''). ''Chaotic Random Number Generators with Random Cycle Lengths''. [http://www.agner.org/random/theory/chaosran.pdf pdf]
* [[Julio César Hernández-Castro]], [https://scholar.google.es/citations?user=0q4BhD8AAAAJ&hl=en Arturo Ribagorda], [https://scholar.google.com/citations?user=BHf4l7wAAAAJ&hl=en Pedro Isasi], [https://dblp.org/pid/56/6864.html José M. Sierra] ('''2001'''). ''[https://www.tandfonline.com/doi/abs/10.1080/0161-110191889897 Genetic Algorithms Can be Used to Obtain Good Linear Congruential Generators]''. [https://en.wikipedia.org/wiki/Cryptologia Cryptologia], Vol. 25, No. 3
* [[Mathematician#GMarsaglia|George Marsaglia]] ('''2002'''). ''[http://digitalcommons.wayne.edu/jmasm/vol2/iss1/2/ Random number generators]''. [https://en.wikipedia.org/wiki/Journal_of_Modern_Applied_Statistical_Methods Journal of Modern Applied Statistical Methods], Vol. 2, No. 2.
* [[Mathematician#GMarsaglia|George Marsaglia]] ('''2003'''). ''[https://www.jstatsoft.org/article/view/v008i14 Xorshift RNGs]''. [https://en.wikipedia.org/wiki/Journal_of_Statistical_Software Journal of Statistical Software], Vol. 8, No. 14
* [[Mathematician#PLEcuyer|Pierre L'Ecuyer]] ('''2004'''). ''Random Number Generation''. [http://www.iro.umontreal.ca/~lecuyer/myftp/papers/handstat.pdf pdf]
* [[Julio César Hernández-Castro]], [https://en.wikipedia.org/wiki/Andr%C3%A9_Seznec André Seznec], [https://scholar.google.com/citations?user=BHf4l7wAAAAJ&hl=en Pedro Isasi] ('''2004'''). ''On the design of state-of-the-art pseudorandom number generators by means of genetic programming''. [https://dblp.org/db/conf/cec/cec2004.html#HernandezSI04 CEC 2004], [https://core.ac.uk/download/pdf/29399623.pdf pdf]
* [[Donald Eastlake]], [[Stephen D. Crocker]], [https://jis.qyv.name/ Jeffrey I. Schiller] ('''2005'''). ''Randomness Requirements for Security''. [https://tools.ietf.org/html/rfc4086 RFC 4086]
* [[Mathematician#WHPress|William H. Press]], [[Mathematician#SATeukolsky|Saul A. Teukolsky]], [https://de.wikipedia.org/wiki/William_T._Vetterling William T. Vetterling], [https://en.wikipedia.org/wiki/Brian_P._Flannery Brian P. Flannery] ('''2007'''). ''[https://en.wikipedia.org/wiki/Numerical_Recipes Numerical Recipes. The Art of Scientific Computing], 3rd edition''. (C++ code)
* [[Mathematician#DJBernstein|Daniel J. Bernstein]] ('''2007'''). ''The Salsa20 family of stream ciphers''. [https://en.wikipedia.org/wiki/University_of_Illinois_at_Chicago University of Illinois at Chicago], [https://cr.yp.to/snuffle/salsafamily-20071225.pdf pdf] <ref>[https://en.wikipedia.org/wiki/Salsa20 Salsa20 from Wikipedia]</ref>
* [[Mathematician#DJBernstein|Daniel J. Bernstein]] ('''2008'''). ''ChaCha, a variant of Salsa20''. [https://en.wikipedia.org/wiki/University_of_Illinois_at_Chicago University of Illinois at Chicago], [http://cr.yp.to/chacha/chacha-20080128.pdf pdf]
==2010 ...==
* [[Maciej Szmit]], [https://dblp.uni-trier.de/pers/hd/s/Szmit:Anna Anna Szmit] ('''2011'''). ''[https://link.springer.com/chapter/10.1007/978-3-642-21771-5_32 DNS Pseudo-Random Number Generators Weakness]''. [https://dblp.uni-trier.de/db/conf/cn/cn2011.html CN 2011], [https://en.wikipedia.org/wiki/Springer_Science%2BBusiness_Media Springer]
* [http://www.talkchess.com/forum/viewtopic.php?t=49807 rkiss and other dependencies in syzygy] by [[Don Dailey]], [[CCC]], October 23, 2013
==2015 ...==
* [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=56225 A simple PRNG using /dev/urandom] by [[Steven Edwards]], [[CCC]], May 04, 2015
* [http://www.talkchess.com/forum/viewtopic.php?t=56328 Revised source for the random game generator] by [[Steven Edwards]], [[CCC]], May 12, 2015
* [http://www.talkchess.com/forum/viewtopic.php?t=56364 Random playout vs evaluation] by [[Robert Pope]], [[CCC]], May 15, 2015
* [http://www.talkchess.com/forum/viewtopic.php?t=61315 Adding a random small number to the evaluation function] by [[Uri Blass]], [[CCC]], September 03, 2016
* [http://www.talkchess.com/forum/viewtopic.php?t=63803 random evaluation perturbation factor] by [[Stuart Cracraft]], [[CCC]], April 24, 2017
* [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=70050 xiphos 64 bit random number] by [[Pedro Castro]], [[CCC]], February 28, 2019 » [[Xiphos]]
==2020 ...==
* [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=74028 Rolling dice] by [[Harm Geert Muller]], [[CCC]], May 27, 2020 » [[Chess Engine Communication Protocol|CECP]], [[EinStein würfelt nicht!]]
=External Links=
* [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]]===
==Misc==
* [[:Category:Van der Graaf Generator|Van der Graaf Generator]] - Theme One (1972), [https://en.wikipedia.org/wiki/YouTube YouTube] Video
: {{#evu:https://www.youtube.com/watch?v=rGHat7IeNaAWWcJ7WeAK78|alignment=left|valignment=top}}
=References=

Navigation menu