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.