Random number generator with blacklisted numbers

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
Bentley-Sama
Newbie
Posts: 2
Joined: Mon Jan 28, 2019 12:35 am
Contact:

Random number generator with blacklisted numbers

#1 Post by Bentley-Sama »

Hello everyone, I was hoping someone could help me figure out a way to make a number generator that doesn't use specific numbers. Such as a generator that won't roll 13 24 27 33 etc... Also if anyone knows of a way to make it where two random numbers generators won't end up with the same number that would be appreciated.
edit:
I appreciate the responses so far! I've solved the first step of the puzzle by using the random.choice() function. I still can't think of a way to make sure two random number generators won't end up with the same number.
An example would be if random1 = renpy.random.choice(1,2,3) rolled and got 2 then random2 = renpy.random.choice(1,2,3) couldn't also roll 2 it would instead either re-roll until it got a number that wasn't taken or somehow remove the previously rolled number from the random pool... Any Ideas? Someone entertained the idea of using random.sample() but I don't know where to start with that idea
Last edited by Bentley-Sama on Mon Oct 21, 2019 3:41 pm, edited 1 time in total.

User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Random number generator with blacklisted numbers

#2 Post by isobellesophia »

Bentley-Sama wrote: Mon Oct 21, 2019 11:39 am Hello everyone, I was hoping someone could help me figure out a way to make a number generator that doesn't use specific numbers. Such as a generator that won't roll 13 24 27 33 etc... Also if anyone knows of a way to make it where two random numbers generators won't end up with the same number that would be appreciated
Maybe rand.int could help, which can randomize things like dialogue and numbers too. I can help if thats what you mean.
I am a friendly user, please respect and have a good day.


Image

Image


drKlauz
Veteran
Posts: 239
Joined: Mon Oct 12, 2015 3:04 pm
Contact:

Re: Random number generator with blacklisted numbers

#3 Post by drKlauz »

You could use renpy.random.choice with list of allowed values.
Or you could make loop what will generate new random number until it is not in blacklist.

First approach is better, unless you want really wide range of values.
I may be available for hire, check my thread: viewtopic.php?f=66&t=51350

User avatar
IrinaLazareva
Veteran
Posts: 399
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy
Organization: SunShI
Location: St.Petersburg, Russia
Contact:

Re: Random number generator with blacklisted numbers

#4 Post by IrinaLazareva »

Bentley-Sama wrote: Mon Oct 21, 2019 11:39 am Someone entertained the idea of using random.sample() but I don't know where to start with that idea

Code: Select all

    $ random1, random2 = renpy.random.sample([1, 2, 3, 4], 2)

Post Reply

Who is online

Users browsing this forum: No registered users