Python || Custom Random Number Generator Class MyRNG

Print Friendly, PDF & Email

The following is sample code for a simple random number generator class. This random number generator is based on the Park & Miller paper “Random Number Generators: Good Ones Are Hard To Find.

This class has three functions. The constructor initializes data members “m_min” and “m_max” which stores the minimum and maximum range of values in which the random numbers will generate.

The “Seed()” function stores the value of the current seed within the class, and the “Next()” function returns a random number to the caller using an algorithm based on the Park & Miller paper listed in the paragraph above. Each time the “Next()” function is called, a new random number is generated and returned to the caller.


QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

===== DEMONSTRATION HOW TO USE =====

Use of the above class is very simple to use. A sample function demonstrating its use is provided on line #64 in the above code snippet.

After running the code, the following is sample output:

SAMPLE OUTPUT:


1037, 1296, 1123, 1900, 1375, 1676, 1798, 662, 664, 674, 746, 1249, 793, 1578, 1112,

Was this article helpful?
👍 YesNo

One Response to Python || Custom Random Number Generator Class MyRNG

  1. Avatar Kelvin Ng says:

    what is the .m_ means?

Leave a Reply to Kelvin NgCancel reply