# How can I determine the period of my pseudo-random number generator?

Suppose I'm using a linear congruential pseudo-random number generator (PRNG). Given a seed $x_0$, the multiplying factor (a), the shift factor (c) and the modulus factor (m), how can I determine the period of my PRNG? Do I determine it by experimentation / pattern detection algorithms, or is there a direct formula for calculating its period?

Although my question is specifically about the linear congruential method, I am open to knowing more about how periods are calculated in practice for other PRNG's as well.

-
 Relevant: en.wikipedia.org/wiki/… – user182 Mar 4 '12 at 17:46 BTW, if you're using LFSR then the period is maximal iff the feedback polynomial is primitive. In such case, the period AFAIK (don't quote me; too lazy to dig up my course notes) is $q^n$ where the feedback polynomial $p(x) \in \mathbb{F}_{q}[x]$ of degree $n$, and $q$ is the size of the field of coefficients. – user182 Mar 6 '12 at 17:31

As J.D. suggests, if you constrain yourself to full cycle LCG PRNGs then the answer is easy, by definition it's simply $m$.

The period of a general LCG is at most $m$, and for some choices of a much less than that. Provided that $c$ is nonzero, the LCG will have a full period for all seed values if and only if:
While LCGs are capable of producing decent pseudorandom numbers, this is extremely sensitive to the choice of the parameters $c$, $m$, and $a$.