only output certain numbers randomly?

cchandler's icon

I have some data associated with 10 indexes in a coll. I am using a random object to randomize which of those indexes are output from the coll.

However, at times, I only want to use certain indexes, for instance 2, 3, 5, and 6, but I want those particular indexes to be chosen randomly.

Any suggestions on how I might randomly choose among only certain predefined numbers?

mzed's icon

I would make a random object with the argument 4, and pass it through a coll with the contents:

0, 2;
1, 3;
2, 5;
3, 6;

Or, more likely, I would make a table with 10 x values. I would set all of the y values to 0 except the ones I want to use (2,3,5, and 6) which I would set to 1. Then I would bang the table.

mz

cchandler's icon

A table is a perfect solution. Thanks mzed!

seejayjames's icon

table is the best, probably. Though if you don't need to change the values, you can always use the "non-matching" rightmost outlet of [rotue] or [select]---if one comes out, re-bang the [random]. as long as *some* value eventually gets selected, you won't get a stack overflow :)

Emmanuel Jourdan's icon
Max Patch
Copy patch and select New From Clipboard in Max.

table is faster indeed. Some efficienty test and others solutions using zl: