How do you simulate a dice roll in python?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • matt murray
    New Member
    • Nov 2010
    • 4

    How do you simulate a dice roll in python?

    I'm writing a text based adventure game and was wondering if there was a way to "Roll Dice". An example of what i am trying to use this for would be attacking or defending in the game. If they get above or equal to a certain number It would be considered a hit. I would also need this same automated dice rolling for the enemies in the game.

    Thanks

    Matt.
  • Joshua Brooks
    New Member
    • Dec 2010
    • 3

    #2
    Sounds like a random number generator is what you need. 'randrange' gives a one-liner to get a random integer:

    from random import randrange
    diceroll = randrange(1,7)

    Comment

    • Sean Pedersen
      New Member
      • Dec 2010
      • 30

      #3
      Nearby topic.

      Comment

      • matt murray
        New Member
        • Nov 2010
        • 4

        #4
        Thanks a lot. Both were a big help.

        Comment

        Working...