Skip to content

Instantly share code, notes, and snippets.

@aristus
Created May 22, 2013 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aristus/5631426 to your computer and use it in GitHub Desktop.
Save aristus/5631426 to your computer and use it in GitHub Desktop.
sampling 10,000 random numbers 1:100
import random
runs = 10000
rate = 100
for _ in range(50):
real_sum = 0
real_cnt = 0
est_sum = 0
est_cnt = 0
for i in range(runs):
r = random.randint(1, 5000)
real_sum += r
real_cnt += 1
if r % rate == 0:
est_sum += r
est_cnt += 1
print real_sum, real_cnt, est_sum * rate, est_cnt * rate
"""
For example:
25182857 10000 21760000 9100
24936166 10000 23400000 9000
25218707 10000 21620000 8900
25151089 10000 29510000 10800
24855485 10000 25790000 10500
25286563 10000 30470000 11500
25155408 10000 25880000 9700
25011022 10000 18190000 8300
25061137 10000 22550000 8600
25121054 10000 25860000 8800
25062352 10000 24660000 9700
25210231 10000 20140000 8200
24946122 10000 26950000 10200
25021020 10000 29570000 10500
25028169 10000 24960000 10300
25027548 10000 24560000 11000
24789947 10000 28840000 10100
25063151 10000 32440000 12600
24672843 10000 23610000 9600
25127861 10000 25350000 9000
25121507 10000 24950000 10000
24873485 10000 25430000 11400
24866325 10000 22290000 8700
25048101 10000 25770000 10200
25090220 10000 23060000 8600
24846262 10000 25410000 10900
25158951 10000 27750000 9500
25295999 10000 22120000 8800
24896047 10000 28860000 11100
24886093 10000 26040000 10200
25138038 10000 26080000 10300
24970214 10000 21200000 9500
24731522 10000 21490000 8800
25002052 10000 25270000 10800
25059618 10000 24610000 8800
24992860 10000 22320000 9600
25051448 10000 27260000 10300
24783547 10000 24840000 9000
25188849 10000 31410000 11900
24993993 10000 23160000 9500
25202740 10000 29590000 11400
24926938 10000 24750000 9900
25155581 10000 26330000 10000
24618778 10000 23770000 9600
24718896 10000 28140000 10500
25225766 10000 30530000 11600
24821866 10000 27130000 10300
24915421 10000 28870000 11200
24940089 10000 21560000 9300
25199300 10000 28330000 11100
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment