Home * Programming * Algorithms * Pseudorandom Number Generator
Pompeii_-_Osteria_della_Via_di_Mercurio_-_Dice_Players.jpg

Pseudorandom Number Generator (PRNG),
an algorithmic gambling device for generating pseudorandom numbers, a deterministic sequence of numbers which appear to be random with the property of reproducibility. They are useful in simulation, sampling, computer programming, decision making, cryptography, aesthetics and recreation [1] - in computer chess, beside randomization of game playing, primarily used to generate keys for Zobrist hashing.

Games of chance, such as Backgammon and EinStein würfelt nicht! require PRNGs for rolling a dice. Chess and game playing programs use PRNGs to randomly choose one of several possible moves of a position from an opening book, or use random fluctuations in learning and automated tuning tasks. Game playing programs performing a Monte-Carlo Tree Search, use random playouts in their simulation phase. Don Beal and Martin C. Smith demonstrated that deeper search with random leaf values in chess yields to better play, with some interesting insights in minimax search and implications for designing and testing evaluation terms [2].
Dice players [3]

Methods

PRNGs maintain a state variable, a bitwise superset of the random number, initialized by a random seed - a constant for the same sequence each time, i.e. for Zobrist keys, otherwise, something like system time to produce varying pseudo randoms. Each call of the PRNG routine performs certain operations or bit-twiddling on that state, leaving the next pseudo random number. For various applications more or less important features are randomness, resolution, (uniform) distribution, and periodicity - topic of various randomness tests - and further performance, and portability.

A common method used in many library functions, such as C/C++ rand() is the linear congruential generator based on multiply, add, modulo with integers, where some past implementations had serious shortcomings in the randomness, distribution and period of the sequence [4]. Due to such issues in rand() implementations, where lower bits are less random than higher bits, it is recommended not to use modulo X to reduce the integer range from RAND_MAX to X, but division by (RAND_MAX div X) [5] - or to use C++11's random number generation facilities to replace rand [6].

Zobrist hashing with about 12*64 keys has less issues with randomness and period, but with distribution, and requires linear independence 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 recurrence relation in GF(2) such as Mersenne Twister or Xorshift. Stockfish (since 2.0) uses an implementation by Heinz van Saanen based on Bob Jenkins' RKISS, a member of George Marsaglia's Xorshift familly. Amy by Thorsten Greiner [7] uses an implementation of Agner Fog's RANROT B3 [8], also recommended by Stefan Meyer-Kahlen as used in Shredder [9]. Arasan 20.x switched to C++11 random number support using std::mt19937_64 [10] [11]

Applications


See also


Selected Publications

1950 ...

1960 ...

1970 ...

1980 ...

1990 ...

2000 ...

2010 ...


Forum Posts

1982 ...

1990 ...

1995 ...

2000 ...

2005 ...

2010 ...

2015 ...


External Links

Randomness

Methods

Language Support

Basic

C

C++

C#

D

Fortran

Go

Java

Lisp

Pascal

Python

Tests

Misc


References

  1. ^ Donald Knuth (1997). The Art of Computer Programming (TAOCP) - Volume 2 - Seminumerical Algorithms. Chapter 3 – Random numbers
  2. ^ Don Beal, Martin C. Smith (1994). Random Evaluations in Chess. Advances in Computer Chess 7
  3. ^ Dice players - Roman fresco from the Osteria della Via di Mercurio (VI 10,1.19, room b) in Pompeii, Source: Filippo Coarelli (ed.) (2002). Pompeji. Hirmer Verlag, Munich, ISBN: 3-7774-9530-1, p. 146, Wikimedia Commons, History of randomness from Wikipedia
  4. ^ "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()." rand - cppreference.com
  5. ^ Re: random book moves/ random generator by Thorsten Greiner, CCC, January 13, 2000
  6. ^ Pseudo-random number generation - cppreference.com
  7. ^ amy-0.8.7.tar.gz /src/random.c
  8. ^ Agner Fog (2001). Chaotic Random Number Generators with Random Cycle Lengths. pdf
  9. ^ Re: random book moves/ random generator by Stefan Meyer-Kahlen, CCC, January 13, 2000
  10. ^ arasan-chess/movegen.h at master · jdart1/arasan-chess · GitHub
  11. ^ mt19937_64 - C++ Reference
  12. ^ Mersenne twister from Wikipedia

What links here?


Up one Level