Sample C99 Code
Using C code, the Lehmer generator using the "popular pair" of parameters mentioned above can be written as follows:
uint32_t lcg_rand(uint32_t a) { return ((uint64_t)a * 279470273UL) % 4294967291UL; }As the product of two 32 bit integers may overflow, the cast to uint64_t is necessary.
Read more about this topic: Lehmer Random Number Generator
Famous quotes containing the words sample and/or code:
“As a rule they will refuse even to sample a foreign dish, they regard such things as garlic and olive oil with disgust, life is unliveable to them unless they have tea and puddings.”
—George Orwell (19031950)
“Acknowledge your will and speak to us all, This alone is what I will to be! Hang your own penal code up above you: we want to be its enforcers!”
—Friedrich Nietzsche (18441900)