Random number generation from a shrinking pool of options

How do I force the instant generation of a set of random integers so that:

  • they are all different from each other
    AND
  • they are all different from a set of excluded numbers (the ones that were generated previously)?

Say I have to generate 3 integers between 1 and 10, all 3 need to be different from each other and they all must also not be 4 or 7; is there a way to generate random numbers following these rules in gamma?

This has been driving me up the wall for the whole day, any and all help would be greatly appreciated! <3

(For context, I need this in order to make a set of buttons that a user has to turn off. It starts from one active button - if you turn it off, 2 more turn on. Then if you turn off a second button, 3 more turn on. And then 4, and 5, and more and more until all buttons are turned on, since the user can only turn off one button at a time, and the buttons turn on at a faster rate than they can be turned off. I need to be able to pick which buttons to turn on randomly, but I also want to leave be the buttons that are already on, removing them from the possible pool of choices for buttons to turn on - they are on already. Is this clear? It’s a bit convoluted…)

Since your rule is random numbers between 1 and 10, you seem to know beforehands, that the maximum numbers possible is actually 9.
use a RandomSpread with count 9, which will give you 9 floats. now sort the sequence and use the former index = the index of the item in the random sequence instead of the actual sorted numbers. this will result in a random sequence of integers which are all unique.

This responds to the first rule (generate random integers different from each other) but not the second (must be different from a set of excluded numbers)

Also I am not generating all 9 at the same time, but a set of 3, then another set of 3 all different from the previous, and then another set of 3 all different from the previous two I generated, at which point I have generated everything I could generate out of 9 possible numbers. It is progressive generation that excludes previously generated results.

I am moving forward with my own trial patches and I think I’m on the cusp of figuring out but once again I’m having trouble with spreads with different numbers of slices hhhh

Also an important element I want to include is that it must be a variable number. I gave numbers from 1 to 10 as an example earlier but I want my generator to be able to account for variable amounts, not be fixed to max 9 numbers.

Also an important element I want to include is that it must be a variable number. I gave numbers from 1 to 10 as an example earlier but I want my generator to be able to account for variable amounts, not be fixed to max 9 numbers.

question is, do you know the number before starting generator?
because if so, that method still works. generate maximum unique random sequence, e.g. 9, then per step take 3 of those until none are left.

if not, just keep on generating random numbers per step, until you hit one which is not in the list of already used numbers before you use it for your user facing logic.

however, since you described the program in your first post as buttons the user should be able to click, i assume, there is some kind of maximum number available (either on screen or physically). so the first method, generating the random sequence before actually starting user interaction of picking from them is the more effective one.

I am making a mock logic example for an installation.

The installation has x number of phones (say, 16 phones) located in a space.
At the beginning one phone gets a (fake) notifications rings. A user in the space dismisses the notification. When that happens, two more phones should start to ring. The user goes to turn off one again and if he does so, three more should start to ring (for a total of four, considering the one that hasn’t been turned off). And so on: whenever the user tries to turn off one, more and more should start turning on, in a progression of 1-2-4-7-11-16 (if I did the maths right).

However, I want the maximum total number of phones in the installation to be variable (it’s been requested to me that I make it this way), so I’m using 16 as an example number that is big yet small enough to think about easily.

And the phones shouldn’t always turn on in the same order, which is where the randomness comes in.

while the ringing is in action. can the number of phones change? or do you go through an interaction cycle (none up until all have changed) until the total number of phones can change?
the interaction seems to have a clear start (no phone has been ringing yet) and a clear end (all phone have been dismissed), right?

no, not all the phones need to be dismissed before the number raises again.

Basically it should go like this is I have 16 phones in my installation:
begin:
step 0 (automatic) : 0 phones ringing + 1 progression = 1 phone ringing
step 1: 1 ringing phone - 1 dismissed by user + 2 progression = 2 phones ringing
step 2: 2 ringing phones - 1 dismissed + 3 progression = 4 phones ringing
step 3: 4 ringing phones - 1 dismissed + 4 progression = 7 phones ringing
step 4: 7 ringing phones -1 dismissed + 5 progression = 11 phones ringing
step 5: 11 ringing phones - 1 dismissed + 6 progression = 16 phones ringing
when number of phones ringing >= number of total phones (here it takes 5 steps) then the phones all ring for 10 seconds, then they are all turned off for 10 seconds, then the cycle starts again from step 0

here is one of the trial patches I’ve done until now. If only I knew how to replace multiple slices of a spread at the same time this would work I think:

randomness trials2.vl (33.8 KB)

here you go

RandomSequence.vl (26.2 KB)

starting with a randomized set of indices.
setting first to state ‘ringing’
on dissmiss of a ringing one, pick next ones of the set and set to ringing
repeat

changing the count will trigger reset

1 Like

Holy smokes dude, this is amazing!

I am so happy I turned to the forum, holy… I would’ve lost my mind trying to figure this out, as you have probably seen from my own patch I am self-taught and still have a looot to learn

Thank you so much!!!

Here’s the final logic I went with!
Sorry I hacked away a bit at your beautiful logic to get to my purpose, @woei
And thanks again!

AppLogic Try5.vl (111.4 KB)

1 Like