Advertisement
Guest User

Code for 3-d34 minus 2

a guest
Apr 24th, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. #
  2. # FILE: 3d34.py
  3. #
  4.  
  5. import random
  6.  
  7. def roll34SidedDie():
  8.     """
  9.    Return a random roll from 1-34.
  10.    """
  11.     return random.randint(1, 34)
  12.    
  13. def rollThree34SidedDiceMinusTwo():
  14.     """
  15.    Return 3d34 - 2.
  16.    """
  17.     sum = roll34SidedDie()
  18.     sum += roll34SidedDie()
  19.     sum += roll34SidedDie()
  20.     return sum - 2
  21.    
  22. #
  23. # Roll 3d34 - 2 an number of times and print the results.
  24. #
  25. if __name__ == '__main__':
  26.     random.seed()
  27.     rolls = dict()
  28.     # 1-100 (That's how 'range' works.)
  29.     for aRoll in range(1, 101):
  30.         rolls[aRoll] = 0
  31.     # 10 million rolls
  32.     limit = 10000000
  33.     for aRoll in range(0, limit):
  34.         rolls[rollThree34SidedDiceMinusTwo()] += 1
  35.     results = rolls.keys()
  36.     results.sort()
  37.     for aResult in results:
  38.         print '%3d    %7d' % (aResult, rolls[aResult])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement