August 14th, 2004, 03:07 PM
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?
August 15th, 2004, 06:38 AM
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 .
Last edited by netytan; August 15th, 2004 at 06:42 AM.
August 15th, 2004, 08:39 PM
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.
August 16th, 2004, 05:09 AM
i would do this in that way
number = random.randint(0, 101)
if number == 3: # you can choose any number you want between 1 and 101
print "1% chance"
print "99% chance"
August 16th, 2004, 06:05 AM
Or something like this:
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'
August 19th, 2004, 01:14 AM
thx i would never of thought of using those.