Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Linear Congruential Generator

  1. Oct 28, 2013 #1
    I am trying to understand LCG and although the equation looks really straightforward I don't know how to calculate the module of the expression.

    Xn+1= a*Xn+c (mod m)

    As stated before, my problem is understanding the concept of mod m and how to calculate it.

    Any help and example would be appreciated.
     
  2. jcsd
  3. Oct 28, 2013 #2

    UltrafastPED

    User Avatar
    Science Advisor
    Gold Member

    a*Xn+c Modulo m gives the remainder of a*Xn+c when divided by m.
    See http://en.wikipedia.org/wiki/Modulo_operation

    Most computer programming languages have a "mod" function. In machine language the integer divide will provide the quotient in one register, and the remainder in another - this makes this very fast. This is a very old pseudo-random number generator which was already in use in the 1950's - I used to have an IBM publication copyright 1953 or so which provided all of the details.

    http://en.wikipedia.org/wiki/Linear_congruential_generator
     
  4. Oct 28, 2013 #3

    mathman

    User Avatar
    Science Advisor
    Gold Member

    Typical random number generators will use integer arithmetic, where m is 2k, where k = 1+largest single precision integer. a*Xn+c will produce an integer covering a double precision register. Keep the lower half.

    The above method then is followed by division (after floating) by the float of k.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Linear Congruential Generator
  1. Generating Functions (Replies: 5)

Loading...