Thread: dice roll

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Knighton Uk
    Posts
    17
    Rep Power
    0

    dice roll


    hey, u know how u are i need the script to make that dice roll program again...

    my msn is playing up..
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,607
    Rep Power
    4247
    Code:
    #!/usr/bin/env python
    import rand
    
    def getroll():
        die = rand.rand() % 6 + 1
        return die
    
    die1 = getroll()
    die2 = getroll()
    
    print "Die 1: ", die1, " Die 2: ", die2, " Total: ", die1 + die2
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. onCsdfeu
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Canada
    Posts
    100
    Rep Power
    12
    You could've used
    Code:
    die = random.randint(1,6)
    instead. I just find it more suited to that particular situation. And the module's name's random BTW
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Infact Scorpi your dice role program wont work at all on newer versions of Python since the rand module no longer exists in the standard library.. What version of Python are you running ATM?

    Mark.
    programming language development: www.netytan.com Hula

  8. #5
  9. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Just for those who are interested, Python 1.5.2 was the last version of Python to support the rand module apparently. It seems to have been depreciated since even before version 2!

    Paul Rubin
    The rand module also disappeared, completely gratuitously as far as I can tell. That's what broke the Redhat scripts.

    Aahz
    The rand module was already deprecated in 1.5.2; it's in
    Lib/lib-old/rand.py; it's not even in the docs.
    It is still in Pythons doc's, in the "Undocumented Modules" part which simply says..

    rand
    -- Old interface to the random number generator.
    Take care,
    Mark.
    Last edited by netytan; October 30th, 2003 at 03:58 PM.
    programming language development: www.netytan.com Hula

  10. #6
  11. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,607
    Rep Power
    4247
    Actually, it happens that the box I tested the code snippet on is running Python 1.5.2 (on RH 7.1 ). It's the only box I have lying around the office that has python on it. My boxes at home have later versions
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  12. #7
  13. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Ah that explains it then , i'd tell you to update but your one of the redhat guys and we don't wana break anything ..

    Well if were all in agreement you can do the dice thing like this mike:

    Code:
    #!/usr/bin/env python
    
    import random
    
    #role the dice
    die = random.randint(1, 6)
    
    #deside what to do depending on th value of the die. i.e 1, 2, 3, 4, 5, 6
    if die == 1:
        print 'do soemthing when random is',  random
    if die == 2:
        print 'do soemthing else when it is', random
    else:
        print 'do this if random is', random
    well fix it then ,

    have fun,
    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo