Randomizing
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
- Wright1000
- Miko-Class Veteran
- Posts: 629
- Joined: Thu Mar 31, 2011 10:20 am
- Completed: Finding A Murderer, Memory Loss, Crime Investigation, Stay away from the graveyard, Last Day at School, Lonesome, Email, Hired Gun, Dusk, Hired Gun 2, Man-at-arms, Hired Gun 3, The Phantom Caller, Street Girl, Free love, The Story of Isabel Claudia
- Contact:
Randomizing
If I want to randomize something, how do I do it?
For example, I want a non-player character to choose a number between 1 and 10, how is it done?
For example, two non-player characters are playing football. I want to randomize the winner. How is it done?
For example, I want a non-player character to choose a number between 1 and 10, how is it done?
For example, two non-player characters are playing football. I want to randomize the winner. How is it done?
He who doesn't care about the environment doesn't care about his grandchildren.
- Tachyglossus
- Regular
- Posts: 164
- Joined: Wed Dec 01, 2010 7:43 pm
- Projects: Sprite Art for: "Final Banquet", "365 Days"
- Location: British Columbia
- Contact:
Re: Randomizing
Ooooh speaking of randoms, this is a purely theoretical question, but is it possible to make it pull a random element from a list, but attach a greater probability to certain items for being chosen?
Using the fruit example in the reference, say you wanted oranges to be twice as more likely to be picked than apples or plums, would that be possible?
Using the fruit example in the reference, say you wanted oranges to be twice as more likely to be picked than apples or plums, would that be possible?
Re: Randomizing
Mmm..., the easiest way is to add twice more oranges in a list, so the probability of choosing an orange from that list would be twice greater.
More complicated way described in a Cookbook.
More complicated way described in a Cookbook.
-
pondrthis
- Veteran
- Posts: 265
- Joined: Tue Dec 14, 2010 5:20 pm
- Completed: G-Senjou no Maou Translation
- Location: Nashville, TN
- Contact:
Re: Randomizing
Out of further curiosity, is there no built-in generator for the normal distribution? (I'm obviously changing the topic from discrete to continuous space with this question, but it's only a matter of rounding.)
- PyTom
- Ren'Py Creator
- Posts: 15893
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: Randomizing
Ren'Py gives you all of the functions in the Python random module. It looks like the gauss function is the one you want - so renpy.random.gauss.
http://docs.python.org/library/random.html#random.gauss
http://docs.python.org/library/random.html#random.gauss
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom
Re: Randomizing
I just write a series of "if [variable]" statements, with the range of available answers for [variable] corresponding to each of the possible items. I'm a little rusty with Ren'Py, but I believe it would go something like this:Tachyglossus wrote:Ooooh speaking of randoms, this is a purely theoretical question, but is it possible to make it pull a random element from a list, but attach a greater probability to certain items for being chosen?
Using the fruit example in the reference, say you wanted oranges to be twice as more likely to be picked than apples or plums, would that be possible?
Code: Select all
$ x = renpy.random.randint(1, 100)
if x > 0 and x < 26:
n "You got an apple."
elif x > 25 and x < 51:
n "You got a plum."
elif x > 50:
n "You got an orange."
Plus you can always build on each possibility to make things even more diverse:
Code: Select all
$ x = renpy.random.randint(1, 100)
$ y = renpy.random.randint(1, 3)
if x > 0 and x < 26:
if y == 1:
n "You got an apple."
elif y == 2:
n "You got an orange."
elif y == 3:
n "You got a plum."
else:
n "You were bit by a snake and died."
- Tachyglossus
- Regular
- Posts: 164
- Joined: Wed Dec 01, 2010 7:43 pm
- Projects: Sprite Art for: "Final Banquet", "365 Days"
- Location: British Columbia
- Contact:
Re: Randomizing
Thank you these are all awesome answers I'll save for later use!
Last edited by Tachyglossus on Thu May 19, 2011 12:49 pm, edited 1 time in total.
- Wright1000
- Miko-Class Veteran
- Posts: 629
- Joined: Thu Mar 31, 2011 10:20 am
- Completed: Finding A Murderer, Memory Loss, Crime Investigation, Stay away from the graveyard, Last Day at School, Lonesome, Email, Hired Gun, Dusk, Hired Gun 2, Man-at-arms, Hired Gun 3, The Phantom Caller, Street Girl, Free love, The Story of Isabel Claudia
- Contact:
Re: Randomizing
Thank you, everyone.
Your help was useful.
Your help was useful.
He who doesn't care about the environment doesn't care about his grandchildren.
Who is online
Users browsing this forum: Bing [Bot], _ticlock_



