CS 227 W '05
On RNG test RWN
Here's some Mathematica that might be relevant to Random Number Generation.
First of all, here's an attempt at a LCM:
Oops, we see a period of 20. With m = 100, we should be able to get a period of 100.
What went wrong? The conditions of the maximum period theorem were violated. In particular consider
So condition iii) is ok, i.e. 4 divides both b and m.
Condtion ii) is ok too, the only prime divisors of both b and m are 2 and 5.
Now for condition i)
Aha! c and m are not relatively prime, i.e. they have a common factor (other than 1).
The following Mathematica functions might also be useful in seaching for larger and compatible a, c and m. (They're not hard to find.)
Prime[n] gives the nth prime.
PrimeQ[n] returns whether or not n is prime.
PrimePi[n] gives the number of primes ≤ n.
And, for future reference, PowerMod[
Mathematica functions used: FactorInteger, GCD, Mod, NestList, Prime, PrimePI,PrimeQ, PowerMod
If you find some others to be useful for applying the max period test, let me know.
Created by Mathematica (January 27, 2005)