How does Renpy Random Choice Work?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
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.
Post Reply
Message
Author
User avatar
mugenjohncel
Hentai Poofter
Posts: 2121
Joined: Sat Feb 04, 2006 11:13 pm
Organization: Studio Mugenjohncel
Location: Philippines
Contact:

How does Renpy Random Choice Work?

#1 Post by mugenjohncel »

Just curious... what algorithm does ren'py random choice use? I have this feeling in my gut that it's sometimes not random enough... that or I'm just lucky (unfortunate) enough...

Here's an example... see screenshots

Image
Still no customers...

Image
Still no customers...

Image
Still no customers...

Image
Hmm...

Image
Where is everyone?...

Image
...

I use ren'py choice [a] [d] with [a] customer appears and [d] customer not appears... should be fine but I've been getting a lot of these straight no customers from dawn till dusk lately and in one occasion twice in a row... each turn is random ranging from 2 minutes to 6 minutes... for now, the only solution I could think of is increase the random choices. A bit farfetched but is there a better way to generate random numbers?

"POOF" (Disappears)

User avatar
PyTom
Ren'Py Creator
Posts: 16093
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: How does Renpy Random Choice Work?

#2 Post by PyTom »

Hm... renpy.random is a wrapper around python's random module that generates the same random values when rollback occurs. Python's module uses the MersenneTwister algorithm, which is pretty damn good pseudo-randomness. Here's the result of rolling a 1d6 a million times:

1 166841
2 166650
3 166748
4 166838
5 166703
6 166220

(166666 is the expected value, FWIW)

Probability can be a bit confusing, as unlikely events do happen, especially when you run enough trials. Realize that there's enough meat here to make a college subject.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: How does Renpy Random Choice Work?

#3 Post by KimiYoriBaka »

Is it possible that something in your code is making it get stuck in the same choice? Also, if you want to make sure the user can't get too many instances of no customers, you could try writing the code to self-correct any anomalies. this would definitely help people like me who tend to have bad luck in games of chance on the computer... Of course, to do that you'd need to use renpy random randint and base everything related to it on a variable with an upper limit.

User avatar
mugenjohncel
Hentai Poofter
Posts: 2121
Joined: Sat Feb 04, 2006 11:13 pm
Organization: Studio Mugenjohncel
Location: Philippines
Contact:

Re: How does Renpy Random Choice Work?

#4 Post by mugenjohncel »

KimiYoriBaka wrote:Is it possible that something in your code is making it get stuck in the same choice?
Bingo!... After reviewing the code last night... I finally found the cause... :oops:

Image
Customers (including scheduled events) are now appearing the way I wanted them to be...

"POOF" (Disappears)

Post Reply

Who is online

Users browsing this forum: No registered users