Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/python
- #Stupid dice trick -- add two dice together to eliminate the bias from a bad die
- #even less useful on a computer!
- import random
- random.seed()
- countnice = [0,0,0,0,0,0] # six elements, 0-5, counting the number of 1-6 results
- countbad = [0,0,0,0,0,0]
- countadded = [0,0,0,0,0,0]
- for i in range(1,6000) :
- niceroll = random.randint(1,6) # six sides for our good die
- badroll = random.randint(1,7) # baddie has seven sides, but
- if badroll == 7 : badroll = 6 # we load the die so 6+7 are both 6, bumping its odds up
- added = (niceroll + badroll) % 6 # roll over to 1 if we're over 6
- # oh yeah, the list's elements are numbered from 0, not 1, so subtract 1 from the index
- countnice[niceroll-1] = countnice[niceroll-1] + 1
- countbad[badroll-1] = countbad[badroll-1] + 1
- countadded[added-1] = countadded[added-1] + 1
- # mathematically you should see close to 1000 for each side.
- print "Good die rolled :", countnice
- print "Bad die rolled :", countbad
- print "Added result :", countadded
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement