Randomly activate a fixed number of toggles, deactivate the others

spin lud's icon

Hi!

I have an arbitrary number of toggles, say 10, and a process that sends periodically a bang.

I want that at each bang received, a fixed number of randomly chosen toggles is activated and the others are deactivated. The idea is that these toggles are connected to bypass on/off separate effects in Jitter, so that at each bang a different combination of effects is activated.

Ideally I would like to have:

  • The number of toggles to activate configurable (eg 2, 3, etc).

  • Avoid to repeat combinations in sequence like having combination (1, 2) and at the next bang again combination (1, 2).

Any suggestions on how this could be done?

Wil's icon

I found this on forums a while back- maybe you can modify to your needs

Max Patch
Copy patch and select New From Clipboard in Max.

Roman Thilenius's icon

uzi -> urn -> cycle -> ...

Wil's icon
uzi -> 

(Smiley face)

spin lud's icon

My first attempt using your suggestions. I am not sure why but the indices of the random list don't correspond at what cycle outputs.
Do you think it is possible to not deactivate a toggle if the new generated list contains it? Right now I am always deactivating all toggles before apply the new list.

test-random-toggles.maxpat
Max Patch


Roman Thilenius's icon

cant look a the patch atm.

resetting everything to zero before every new task - is a common and good practice.

Wil's icon

try adding iter -> sel after [t l b]

Max Patch
Copy patch and select New From Clipboard in Max.

also - urn-jb to avoid repetitions which is causing all toggles off

spin lud's icon

Very clever solution , thank you!

The only thing I miss here is to avoid to bang 0 to every toggle. Basically I need to make a set difference between the current random combination, say (1, 3), and the whole set (1, 2, 3, 4, 5) which would give (2, 4, 5) and bang 0 only to these.

spin lud's icon

I am trying with zl.unique or zl.filter, none of them is outputing anything I am not sure why.


zl-unique-test.maxpat
Max Patch

double_UG's icon

.....................................

spin lud's icon

Right, I inverted the inlets 😅

Solution updated!

test-random-toggles-2.maxpat
Max Patch


Wil's icon

Here - just because other solutions might come in handy

uzi for 1

uzi for 0

then join>scramble>listfunnel>spray

Max Patch
Copy patch and select New From Clipboard in Max.

spin lud's icon

Appreciated this solution sir, much cleaner than my previous one. Thank you very much!

Roman Thilenius's icon

so, now i am looking. wil´s look great, but i think a single zl.group will also do.

Wil's icon

yeah I see

Max Patch
Copy patch and select New From Clipboard in Max.

-- if list is static [1 1 0 0 0]

don't need uzi group at all