Tell me more ×
Computational Science Stack Exchange is a question and answer site for scientists using computers to solve scientific problems. It's 100% free, no registration required.

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.

share|improve this question
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

1 Answer

up vote 4 down vote accepted

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

From the referenced wikipedia page:

Period length

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$.

Historically, poor choices had led to ineffective implementations of LCGs. A particularly illustrative example of this is RANDU which was widely used in the early 1970s and lead to many results which are currently being questioned because of the use of this poor LCG.

share|improve this answer
That is true, but I'm not constraining myself to full period LCG PRNG's... I'm curious about the poor choices of a,c, and m, such that the random streams that do not achieve full period. I'd like to be able to know ahead of time, given some a,c, and m, what will the period inevitably be. I know that it is upper bounded by m, but I was wondering if we can do better than that and obtain the exact period. – Paul Mar 5 '12 at 14:34
1  
The problem is, if you don't know that a given LCG is a full cycle PRNG then you could could end up with a generator with an arbitrary number of mutually distinct sequences, some of which could be embarrassingly small. You really don't want to have to check every possible seed value to make sure that it generates a sequence that are long enough for your application. I would strongly recommend that you read the Numerical Recipes chapter on Random Numbers. – Mark Booth Mar 5 '12 at 15:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.