Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Python3

    import random, statistics

    num_of_sims = 10000
    num_of_rolls = 3000
    results = []

    for s in range(num_of_sims):

        sum_of_rolls = 0

        # roll 20 sided dice
        for r in range(num_of_rolls):
            sum_of_rolls += random.randint(1,20)

        # keep track of the average value
        results.append(sum_of_rolls / num_of_rolls)

    print("ave: ", statistics.mean(results)) # which is 10.49915
    print("stdev: ", statistics.stdev(results)) # which is 0.10492
Now where did I put my statistical tables?


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: