# Linear Congruential Generator

1. Oct 28, 2013

### elgitano77

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. Oct 28, 2013

### UltrafastPED

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

3. Oct 28, 2013

### mathman

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.