Ren'Py Examples: Logic and randomization
Page created: 2025-05-05
Randomize your things!
Ren’Py makes methods of the Python random module available through
renpy.random.
To generate a random number, use randint(start, end):
# Generate a number between 0 and 100 $ mynum = renpy.random.randint(0,100) e "I'm thinking of the number [mynum]."
To pick an item from a list, use choice():
# Make a list $ toppings = ['cheese', 'more cheese']; # Pick from the list $ my_topping = renpy.random.choice(toppings) # Or do it all in one line $ my_bread = renpy.random.choice(['rye', 'wheat', 'sourdough']) # Print out the chosen items e "You have chosen [my_topping] on [my_bread]"
Random yes/no choices can also be made with the choice() function if we
provide it a list containing the boolean values True and False:
# Shall we throw the customer's sandwich?
# Pick True or False
if renpy.random.choice([True,False]):
e "I have thrown your sandwich outside!"
else:
e "Here is your sandwich. Enjoy."