Lehmer Random Number Generator - Sample C99 Code

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:

    The present war having so long cut off all communication with Great-Britain, we are not able to make a fair estimate of the state of science in that country. The spirit in which she wages war is the only sample before our eyes, and that does not seem the legitimate offspring either of science or of civilization.
    Thomas Jefferson (1743–1826)

    Faultless honesty is a sine qua non of business life. Not alone the honesty according to the moral code and the Bible. When I speak of honesty I refer to the small, hidden, evasive meannesses of our natures. I speak of the honesty of ourselves to ourselves.
    Alice Foote MacDougall (1867–1945)