Thread: random...

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

    Join Date
    Jul 2004
    Posts
    58
    Rep Power
    11

    random...


    im making a text based game and im using random.randint to choose a random number between 1-3 that is assigned to a different monster. What is the code to make a certain number have a better chance at bieng chosen than the other two numbers?
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Very easy to do, pick a number between 1 and 4 and make two of the numbers point to the same monster - giving that monster double the chance of the remaining two (2 in 4). Or thats the theory .

    Mark.
    Last edited by netytan; August 15th, 2004 at 06:42 AM.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    58
    Rep Power
    11
    yes that is a good idea

    but what if i need a 1% chance for one thing and a 99% chance for another?
    Should i just put 100 different objects in or is there another thing i could do.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Location
    Germany
    Posts
    11
    Rep Power
    0
    i would do this in that way
    Code:
    import random
    
    number = random.randint(0, 101)
    if number == 3: # you can choose any number you want between 1 and 101
        print "1% chance"
    else:
        print "99% chance"
  8. #5
  9. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Or something like this:
    Code:
    import random
    
    num = random.random(0,101)
    
    if num <= 50: # 50% probable
        monster = 'A'
    elif num >= 51 and num <= 80: # 30% probable
        monster = 'B'
    elif num >= 81 and num <= 90: # 10% probable
        monster = 'C'
    else: # 10% probable
        monster = 'D'
    grim
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    58
    Rep Power
    11
    thx i would never of thought of using those.

IMN logo majestic logo threadwatch logo seochat tools logo