Search code examples
randomglibc

Switch PRNG type in glibc


Looking at glibc source I see that it has five types of pseudo-random number generator implementations — TYPE's from 0 (being linear congruental) through 4. Besides, I can't find any clear examples of how to switch between ones. The default TYPE is 3, as documentation says. Would you please provide me with a simple example of how to switch to e.g. TYPE 4 PRNG?


Solution

  • You call initstate or initstate_r with an array of 8, 32, 64, 128, or 256 bytes which will correspond to initializing the PRNG to the TYPE 0 ... TYPE_4 algorithm.