xaviermontenegro

Untitled

Jul 17th, 2013
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. from random import randint
  2.  
  3. def chance(probability):
  4.     # Make this
  5.  
  6. def test_chance(probability):
  7.     total_rolls = 10000
  8.     positives = 0
  9.     for roll in range(1, total_rolls):
  10.         if chance(probability):
  11.             positives += 1
  12.     print "Achieved %d frequency (%d/%d) with probability of %d" % ((positives / float(total_rolls))*100, positives, total_rolls, probability)
  13.  
  14. test_chance(50) # Should output frequency close to 50
  15. test_chance(25) # Should output frequency close to 25
  16. test_chance(11) # Should output frequency close to 11
Add Comment
Please, Sign In to add comment