Advertisement
Guest User

Dice.py

a guest
Sep 3rd, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. #!/bin/python
  2. #Stupid dice trick -- add two dice together to eliminate the bias from a bad die
  3. #even less useful on a computer!
  4.  
  5. import random
  6.  
  7. random.seed()
  8.  
  9. countnice = [0,0,0,0,0,0] # six elements, 0-5, counting the number of 1-6 results
  10. countbad = [0,0,0,0,0,0]
  11. countadded = [0,0,0,0,0,0]
  12.  
  13. for i in range(1,6000) :
  14.  niceroll = random.randint(1,6) # six sides for our good die
  15.  badroll = random.randint(1,7) # baddie has seven sides, but
  16.  if badroll == 7 : badroll = 6 # we load the die so 6+7 are both 6, bumping its odds up
  17.  added = (niceroll + badroll) % 6 # roll over to 1 if we're over 6
  18. # oh yeah, the list's elements are numbered from 0, not 1, so subtract 1 from the index
  19.  countnice[niceroll-1] = countnice[niceroll-1] + 1
  20.  countbad[badroll-1] = countbad[badroll-1] + 1
  21.  countadded[added-1] = countadded[added-1] + 1
  22. # mathematically you should see close to 1000 for each side.
  23.  
  24. print "Good die rolled :", countnice
  25. print "Bad die rolled  :", countbad
  26. print "Added result    :", countadded
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement