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))
I 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):