Question: Part Five - Analysis How do you know that a RNG is working well enough? There are quite a few tests that mathematicians run to
Part Five Analysis
How do you know that a RNG is working well enough? There are quite a few tests that mathematicians run to ensure they have a good setup for RNGs We will only run two very simple tests, as we are simply learning about how these algorithms work.
In your rngpy file, add a class called Analyzer.
Instance Variables:
max: maximum value returned by the RNG integer
min: minimum value returned by the RNG integer
average: average valure returned by the RNG float
period: period of the RNG integer
bitfreqs: list of integers containing the frequency of bits in the numbers returned by the RNG This list should be ordered from least significant bit to most significant bit.
Methods:
initself randnumgen: constructor, where randnumgen is an instance of one of your RNGs This means you will need to create the RNG before creating an instance of the Analyzer.
analyzeself maxnumse: method that iterates over the RNG given to it until the RNG stops iteration or it has generated maxnums numbers.
The list bitfrequencies is the trickiest. We need to figure out the largest number our RNG will return, then count the number of bits required to store that number. For instance, if the largest number our RNG will return is then we would need
six bits to store the largest value. So we would create
bitfreqs for in range
to hold counters for each of the bits. Then, for each number the RNG returns we would get the binary representation read the python binary documentation. For instance, if the RNG returned
the bit representation would be
Bit:
So we would add one to the counter in bitfreqs bitfreqs and bitfreqs At the end of the analysis sequence when the RNG stops iteration or has produced maxnums numbers the bitfreqs list will tell us how often each bit was used in the overall sequence. We call this the Monobit Test. A truly random sequence should have a uniform distribution meaning each bit is just as likely as the next to be used. In practice though, this is rarely the case. Here is an example from a very poor RNG test I performed this example turned the frequencies into percentages by dividing each by the total number of numbers seen
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
