Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- def chance(probability):
- # Make this
- def test_chance(probability):
- total_rolls = 10000
- positives = 0
- for roll in range(1, total_rolls):
- if chance(probability):
- positives += 1
- print "Achieved %d frequency (%d/%d) with probability of %d" % ((positives / float(total_rolls))*100, positives, total_rolls, probability)
- test_chance(50) # Should output frequency close to 50
- test_chance(25) # Should output frequency close to 25
- test_chance(11) # Should output frequency close to 11
Add Comment
Please, Sign In to add comment