only output certain numbers randomly?

Jan 17, 2011 at 5:36pm

only output certain numbers randomly?

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?

#54228
Jan 17, 2011 at 5:46pm

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

#195177
Jan 17, 2011 at 5:57pm

A table is a perfect solution. Thanks mzed!

#195178
Jan 17, 2011 at 6:55pm

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 :)

#195179
Jan 18, 2011 at 11:09am

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

– Pasted Max Patch, click to expand. –
#195180

You must be logged in to reply to this topic.