Pure Programmer
Blue Matrix


Cluster Map

Project: Central Limit Theorem

The [[Central_limit_theorem#Classical_CLT|Central Limit Theorem]] states that if we take random samples of size N from any distribution of independent random variables, that the distribution of sample averages (`bar X`) should fall in a normal distribution regardless of the type of distribution of the samples. For example our typical random number generators use a uniform, not normal, distribution. But if we take samples of size N, average them, then we should get a sample distribution that is normal with a mean that is the same as our sample source distribution mean and a standard deviation that is equal to the standard deviation of our sample source distribution divided by `sqrt(N)`.

Write a program that accepts a sample size N on the command line and the number of samples to collect M. Then generate the mean (`bar X`) of a sample of size N from random float values [0, 20). Do this M times maintaining a running count of the occurances in an array of 20 by using `lfloor bar X rfloor` (use floor() or int() function) to select the array element to increment. Output a tab-delimited table with the array index in column 1 and the count in column 2. This output can easily be piped into the Histogram project to get a simple graph that should look like a normal distribution centered on 10.0. Notice how as the sample size increases, the standard deviation shrinks?

Output
$ python3 CentralLimitTheorem.py 3 1000 0 0 1 6 2 9 3 17 4 31 5 63 6 67 7 85 8 108 9 108 10 125 11 104 12 92 13 71 14 40 15 41 16 19 17 9 18 5 19 0 $ python3 CentralLimitTheorem.py 5 1000 0 0 1 0 2 1 3 8 4 17 5 37 6 54 7 79 8 135 9 155 10 146 11 126 12 98 13 63 14 41 15 22 16 11 17 6 18 1 19 0 $ python3 CentralLimitTheorem.py 10 1000 0 0 1 0 2 0 3 0 4 1 5 11 6 37 7 84 8 166 9 210 10 188 11 148 12 96 13 40 14 15 15 3 16 1 17 0 18 0 19 0 $ python3 CentralLimitTheorem.py 25 1000 0 0 1 0 2 0 3 0 4 0 5 1 6 3 7 28 8 147 9 316 10 307 11 152 12 44 13 2 14 0 15 0 16 0 17 0 18 0 19 0

Solution