EROF Week 10 – Random Number Generator

Linear CongruentialAlgorithmn

For the meditation this week, I adapted the linear congruential algorithm to make a pseudo-random number generator. Though a basic method, this algorithm is widely used in various occasions. The core equation is here:

X_{n+1}=\left(aX_{n}+c\right)~~{\bmod {~}}~m

Magic Numbers

The argument a, c and m determines the quality of the generator. You can see these three numbers in a lot of articles: 9301, 49297 and 233280. I did some research and found that these three magic numbers are not chosen randomly.

To ensure the quality of the generator, certain conditions must be met:

  1. c and m are coprime;
  2. a – 1 can be divided by all the prime numbers of m
  3. if m is a multiple of 4, so must a – 1

The magic numbers mentioned above are qualified for all of the rules above, thus ensuring the quality of the number generated.

You can see the difference between versions with the magic numbers and with my own numbers:

My Numbers
Magic Numbers

Leave a Reply