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:
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:
- c and m are coprime;
- a – 1 can be divided by all the prime numbers of m
- 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.