Hello,
So I recently did an assignment for an introductory programming course (in Python) where we a number of random numbers and count the number of positive, negative, and zero values and then calculate the average. The range of the numbers generated was -max <= integer <= max. What was interesting to me about this problem was that:
Quote:
If the random number generator is good, we would expect the numbers to be generated uniformly across the range. If the number of random numbers generated is large (e.g. 1000) and your program is correct, we would expect the number of positives to roughly equal the number of negatives and the average to be zero in about nine runs out of ten.
The following is sample output the program produced. As you can see, the positive and negative values are pretty much equal to each other and the average is 0.
code: |
Enter the number of random numbers to be generated: 1234567890
Enter the maximum integer number to be generated: 50
Sum of the random numbers generated: -1225505
Average of the random numbers generated: -0.0
Number of positive numbers generated: 611152683
Number of negative numbers generated: 611195939
Number of zero values generated: 12219268
|
Does this result purely from probability (which would mean this would same result would occur in other languages) or is it the way the Python random generator is designed?