3 ms·
Instead of performing trials in an experiment, another way to look at this problem is to simply analyze the frequency distribution of the leading significant di
by susam 7y ago
Instead of performing trials in an experiment, another way to look at this problem is to simply analyze the frequency distribution of the leading significant digit for a function that grows exponentially. Like before, let us choose 2^n as that function.
Here is the code:
import random
N = 10
counts = [0] * 10
for n in range(N):
first_digit = int(str(2**n)[0])
counts[first_digit] += 1
for i, count in enumerate(counts):
print('{} => {:.3f}'.format(i, counts[i] / N))
For N = 10, i.e., 0 < n < 10, we get:
0 => 0.000
1 => 0.300
2 => 0.200
3 => 0.100
4 => 0.100
5 => 0.100
6 => 0.100
7 => 0.000
8 => 0.100
9 => 0.000
For N = 100, i.e., 0 < n < 100, we get:
0 => 0.000
1 => 0.300
2 => 0.170
3 => 0.130
4 => 0.100
5 => 0.070
6 => 0.070
7 => 0.060
8 => 0.050
9 => 0.050
For N = 1000, i.e., 0 < n < 1000, we get:
0 => 0.000
1 => 0.301
2 => 0.176
3 => 0.125
4 => 0.097
5 => 0.079
6 => 0.069
7 => 0.056
8 => 0.052
9 => 0.045
For N = 10000, i.e., 0 < n < 10000, we get:
0 => 0.000
1 => 0.301
2 => 0.176
3 => 0.125
4 => 0.097
5 => 0.079
6 => 0.067
7 => 0.058
8 => 0.051
9 => 0.046
These results are consistent with the experimental results in my previous comment. As we can see, the larger N is, the more the frequencies of the leading digit obey Benford's law. Similar results can be reproduced with many other exponentially increasing functions too, e.g., 3^n, 5^n, Fibonacci numbers, Lucas numbers, and even factorials that grow faster than exponential functions.
- dmurray 7y agoYou keep choosing N to be an integer power of 10. Make it a power of 2 or 7 or pretty much any number, and you'll see different results.
- susam 7y agoI do not see different results: import random N = 8192 counts = [0] * 10 for n in range(N): first_digit = int(str(2**n)[0]) counts[first_digit] += 1 for i, count in enumerate(counts): print('{} => {:.3f}'.format(i, counts[i] / N)) Output: 0 => 0.000 1 => 0.301 2 => 0.176 3 => 0.125 4 => 0.097 5 => 0.079 6 => 0.067 7 => 0.058 8 => 0.051 9 => 0.046 I still see results that agree with Benford's law.
- logicallee 7y agoI did something similar (except you're a better coder, haha), but when I looked up how to get a random number in Python the first thing I saw was how to get one between 0 and 1 so I went with it. Here is my comment (very similar in spirit to yours): https://news.ycombinator.com/item?id=22341416 https://news.ycombinator.com/item?id=22341416 Any comments?
- susam 7y agoReplied on your comment thread.