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:

    All that a city will ever allow you is an angle on it—an oblique, indirect sample of what it contains, or what passes through it; a point of view.
    Peter Conrad (b. 1948)

    Many people will say to working mothers, in effect, “I don’t think you can have it all.” The phrase for “have it all” is code for “have your cake and eat it too.” What these people really mean is that achievement in the workplace has always come at a price—usually a significant personal price; conversely, women who stayed home with their children were seen as having sacrificed a great deal of their own ambition for their families.
    Anne C. Weisberg (20th century)