Skip to content

Instantly share code, notes, and snippets.

/e.py

Created December 6, 2013 11:08
Show Gist options
  • Save anonymous/7822057 to your computer and use it in GitHub Desktop.
Save anonymous/7822057 to your computer and use it in GitHub Desktop.
Experiment on random.randrange
import random
i = 0
ratio = {}
rounds = 10000000
while i < rounds:
r = random.randrange(1, 11)
if r in ratio:
ratio[r] = ratio[r] + 1
else:
ratio[r] = 1
i = i + 1
for item in ratio:
print (str(item) + ': ' + str((ratio[item] / float(rounds)) * 100) + '%')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment