question about "random" selection

Apr 19, 2008 at 7:08am

question about "random" selection

Hello
Im enquiring about the random selection criteria I am playing with in my patch. Below I will paste the patch so you can clearly see what I am talking about, but what I want my random number generator to do is select a number that isnt already selected… So current I have four different groups with 4 radio buttons. i have a random query going to each which is fine. but what happens is that there is the high chance that becuase there are 4 different randoms they will pick the same numbered radio button… so for instance 1224 or something. so two of the random queries have picked the number 2 in two different groups. i would like something that choses a random number but one that hasnt been chosen so each time the random is requested the radio number is unique within each set.. wow that confusing i hope someone knows what i am on about – see the patch if someone can help me: thanks in advance

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P comment 19 291 79 9109513 preset value;
#P window linecount 3;
#P comment 99 58 79 9109513 CLICK ME TO START RANDOM SHOW;
#P toggle 80 67 15 0;
#P window linecount 1;
#P comment 318 211 79 9109513 random range;
#P slider 256 44 13 51 0 1;
#P hidden newex 255 118 30 9109513 * 120;
#P number 255 148 33 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 3;
#P comment 274 49 79 9109513 change metro: sets time in milliseconds;
#P window linecount 1;
#P hidden newex 212 174 50 9109513 metro 500;
#P hidden newex 330 279 39 9109513 random;
#P hidden newex 383 280 39 9109513 random;
#P hidden newex 279 281 39 9109513 random;
#P number 279 209 35 9 1 4 3 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P hidden button 208 226 15 0;
#P hidden newex 225 282 39 9109513 random;
#P button 102 290 15 0;
#P window setfont “Proportional Serif” 12.;
#P comment 389 460 65 9175052 Lower-right;
#P comment 312 460 59 9175052 Lower-left;
#P comment 229 460 66 9175052 Upper-right;
#P comment 151 460 60 9175052 Upper-left;
#P window setfont “Fixedwidth Serif” 12.;
#P message 166 286 15 9240588 0;
#P message 151 286 15 9240588 1;
#P message 136 286 15 9240588 1;
#P message 121 286 15 9240588 0;
#P hidden newex 134 557 71 9240588 s routeit;
#P hidden message 363 534 78 9240588 patch $1 3;
#P user radiogroup 371 460 18 64;
#X size 4;
#X offset 16;
#X inactive 0;
#X itemtype 0;
#X flagmode 0;
#X set 1;
#X done;
#P hidden message 288 534 78 9240588 patch $1 2;
#P user radiogroup 294 460 18 64;
#X size 4;
#X offset 16;
#X inactive 0;
#X itemtype 0;
#X flagmode 0;
#X set 2;
#X done;
#P hidden message 207 534 78 9240588 patch $1 1;
#P user radiogroup 211 460 18 64;
#X size 4;
#X offset 16;
#X inactive 0;
#X itemtype 0;
#X flagmode 0;
#X set 1;
#X done;
#P hidden message 134 534 78 9240588 patch $1 0;
#P user radiogroup 134 460 18 64;
#X size 4;
#X offset 16;
#X inactive 0;
#X itemtype 0;
#X flagmode 0;
#X set 3;
#X done;
#P hidden newex 121 161 64 9240588 loadbang;
#P hidden connect 21 0 19 1;
#P hidden connect 21 0 22 1;
#P hidden connect 21 0 24 1;
#P hidden connect 21 0 23 1;
#P hidden connect 20 0 19 0;
#P hidden connect 20 0 22 0;
#P hidden connect 20 0 24 0;
#P hidden connect 20 0 23 0;
#P hidden connect 18 0 10 0;
#P hidden connect 18 0 11 0;
#P hidden connect 18 0 12 0;
#P hidden connect 18 0 13 0;
#P hidden connect 0 0 10 0;
#P hidden fasten 0 0 11 0 126 196 141 196;
#P hidden fasten 0 0 12 0 126 196 156 196;
#P hidden fasten 0 0 13 0 126 196 171 196;
#P hidden connect 31 0 25 0;
#P hidden connect 23 0 7 0;
#P hidden connect 24 0 5 0;
#P hidden connect 22 0 3 0;
#P hidden connect 19 0 1 0;
#P hidden fasten 13 0 7 0 171 342 376 342;
#P hidden connect 7 0 8 0;
#P hidden connect 29 0 28 0;
#P hidden fasten 12 0 5 0 156 362 299 362;
#P hidden connect 5 0 6 0;
#P hidden connect 28 0 27 0;
#P hidden connect 27 0 25 1;
#P hidden fasten 11 0 3 0 141 390 216 390;
#P hidden connect 3 0 4 0;
#P hidden connect 25 0 20 0;
#P hidden connect 2 0 9 0;
#P hidden fasten 4 0 9 0 212 582 139 582;
#P hidden fasten 6 0 9 0 293 590 139 590;
#P hidden fasten 8 0 9 0 368 598 139 598;
#P hidden connect 1 0 2 0;
#P hidden fasten 10 0 1 0 126 411 139 411;
#P window clipboard copycount 34;

#37017
Apr 19, 2008 at 10:05am

check the patch below. If you don’t want the mxj object you can use 3 [zl mth] objects in combination with [random] but i think it looks better with the java class.
Anyway… check out also urn if you haven’t done so allready. It’s not exactly what you need but it is good to know that it exists (for the future)

george

#P window setfont “Proportional Serif” 12.;
#P window linecount 1;
#P comment 737 438 65 9175052 Lower-right;
#P comment 660 438 59 9175052 Lower-left;
#P comment 577 438 66 9175052 Upper-right;
#P comment 499 438 60 9175052 Upper-left;
#P user radiogroup 719 438 18 64;
#X size 4;
#X offset 16;
#X inactive 0;
#X itemtype 0;
#X flagmode 0;
#X set 2;
#X done;
#P user radiogroup 642 438 18 64;
#X size 4;
#X offset 16;
#X inactive 0;
#X itemtype 0;
#X flagmode 0;
#X set 3;
#X done;
#P user radiogroup 559 438 18 64;
#X size 4;
#X offset 16;
#X inactive 0;
#X itemtype 0;
#X flagmode 0;
#X set 0;
#X done;
#P user radiogroup 482 438 18 64;
#X size 4;
#X offset 16;
#X inactive 0;
#X itemtype 0;
#X flagmode 0;
#X set 1;
#X done;
#P window setfont “Sans Serif” 9.;
#P newex 524 260 159 9109513 t l b;
#P newex 685 361 50 9109513 random 2;
#P newex 645 392 50 9109513 zl mth;
#P newex 624 326 50 9109513 random 3;
#P newex 584 355 50 9109513 zl mth;
#P newex 564 295 50 9109513 random 4;
#P newex 524 321 50 9109513 zl mth;
#P newex 137 385 70 9109513 unpack 0 1 2 3;
#P message 323 205 50 9109513 0 1 2 3;
#P newex 137 360 72 9109513 mxj list.Shuffle;
#P window linecount 3;
#P comment 278 79 79 9109513 CLICK ME TO START RANDOM SHOW;
#P toggle 323 125 15 0;
#P number 361 127 33 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 356 86 79 9109513 change metro: sets time in milliseconds;
#P window linecount 1;
#P newex 323 153 50 9109513 metro 500;
#P button 323 181 15 0;
#P window setfont “Proportional Serif” 12.;
#P comment 293 439 65 9175052 Lower-right;
#P comment 216 439 59 9175052 Lower-left;
#P comment 133 439 66 9175052 Upper-right;
#P comment 55 439 60 9175052 Upper-left;
#P user radiogroup 275 439 18 64;
#X size 4;
#X offset 16;
#X inactive 0;
#X itemtype 0;
#X flagmode 0;
#X set 0;
#X done;
#P user radiogroup 198 439 18 64;
#X size 4;
#X offset 16;
#X inactive 0;
#X itemtype 0;
#X flagmode 0;
#X set 1;
#X done;
#P user radiogroup 115 439 18 64;
#X size 4;
#X offset 16;
#X inactive 0;
#X itemtype 0;
#X flagmode 0;
#X set 3;
#X done;
#P user radiogroup 38 439 18 64;
#X size 4;
#X offset 16;
#X inactive 0;
#X itemtype 0;
#X flagmode 0;
#X set 2;
#X done;
#P window setfont “Sans Serif” 20.;
#P comment 388 323 38 9109524 OR;
#P connect 24 1 19 0;
#P connect 24 1 21 0;
#P connect 24 1 23 0;
#P fasten 16 0 15 0 328 243 142 243;
#P fasten 16 0 24 0 328 242 529 242;
#P connect 22 1 28 0;
#P connect 22 0 27 0;
#P connect 20 0 26 0;
#P connect 18 0 25 0;
#P connect 24 0 18 0;
#P connect 23 0 22 1;
#P connect 21 0 20 1;
#P connect 20 1 22 0;
#P connect 18 1 20 0;
#P connect 19 0 18 1;
#P connect 15 0 17 0;
#P connect 17 3 4 0;
#P connect 17 2 3 0;
#P connect 17 1 2 0;
#P connect 17 0 1 0;
#P connect 9 0 16 0;
#P connect 10 0 9 0;
#P connect 12 0 10 1;
#P connect 13 0 10 0;
#P window clipboard copycount 33;

#127430
Apr 19, 2008 at 12:01pm

Basically you want to have different random permutations of the four values 0 1 2 3.

You can build that with a [urn 4] object, or better still with [lp.crabelms 0 1 2 3] from Litter Power.

lp.crabelms is the (new! improved!) reincarnation of James McCarthy’s orphaned scramble object (do not try to make an anagram of the word crabelms!). It does what the name says: scrambles the elements of a list.

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 212 259 79 196617 unpack 0 0 0 0;
#P message 212 209 44 196617 0 1 2 3;
#P newex 212 231 64 196617 lp.crabelms;
#P comment 19 291 79 196617 preset value;
#P window linecount 3;
#P comment 99 58 79 196617 CLICK ME TO START RANDOM SHOW;
#P toggle 80 67 15 0;
#P slider 256 44 13 51 0 1;
#P window linecount 1;
#P newex 255 118 44 196617 * 120;
#P number 255 148 33 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 3;
#P comment 274 49 79 196617 change metro: sets time in milliseconds;
#P window linecount 1;
#P newex 212 174 64 196617 metro 500;
#P button 102 290 15 0;
#P window setfont “Proportional Serif” 12.;
#P comment 389 460 65 1020198924 Lower-right;
#P comment 312 460 59 1020198924 Lower-left;
#P comment 229 460 66 1020198924 Upper-right;
#P comment 151 460 60 1020198924 Upper-left;
#P window setfont “Fixedwidth Serif” 12.;
#P message 166 286 15 1441804 0;
#P message 151 286 15 1441804 1;
#P message 136 286 15 1441804 1;
#P message 121 286 15 1441804 0;
#P newex 134 557 71 1441804 s routeit;
#P message 363 534 78 1441804 patch $1 3;
#P user radiogroup 371 460 18 64;
#X size 4;
#X offset 16;
#X inactive 0;
#X itemtype 0;
#X flagmode 0;
#X set 0;
#X done;
#P message 288 534 78 1441804 patch $1 2;
#P user radiogroup 294 460 18 64;
#X size 4;
#X offset 16;
#X inactive 0;
#X itemtype 0;
#X flagmode 0;
#X set 2;
#X done;
#P message 207 534 78 1441804 patch $1 1;
#P user radiogroup 211 460 18 64;
#X size 4;
#X offset 16;
#X inactive 0;
#X itemtype 0;
#X flagmode 0;
#X set 1;
#X done;
#P message 134 534 78 1441804 patch $1 0;
#P user radiogroup 134 460 18 64;
#X size 4;
#X offset 16;
#X inactive 0;
#X itemtype 0;
#X flagmode 0;
#X set 3;
#X done;
#P newex 121 161 64 1441804 loadbang;
#P connect 29 3 7 0;
#P connect 29 2 5 0;
#P connect 29 1 3 0;
#P connect 29 0 1 0;
#P connect 27 0 29 0;
#P connect 19 0 28 0;
#P connect 28 0 27 0;
#P fasten 10 0 1 0 126 411 139 411;
#P connect 1 0 2 0;
#P fasten 8 0 9 0 368 598 139 598;
#P fasten 6 0 9 0 293 590 139 590;
#P fasten 4 0 9 0 212 582 139 582;
#P connect 2 0 9 0;
#P connect 3 0 4 0;
#P fasten 11 0 3 0 141 390 216 390;
#P connect 21 0 19 1;
#P connect 22 0 21 0;
#P connect 5 0 6 0;
#P fasten 12 0 5 0 156 362 299 362;
#P connect 23 0 22 0;
#P connect 7 0 8 0;
#P fasten 13 0 7 0 171 342 376 342;
#P connect 24 0 19 0;
#P fasten 0 0 13 0 126 196 171 196;
#P fasten 0 0 12 0 126 196 156 196;
#P fasten 0 0 11 0 126 196 141 196;
#P connect 0 0 10 0;
#P connect 18 0 13 0;
#P connect 18 0 12 0;
#P connect 18 0 11 0;
#P connect 18 0 10 0;
#P window clipboard copycount 30;

#127431
Apr 20, 2008 at 2:50am

thank you for your replies guys! im going to use the shuffle item just for its simplicity and time (havnt got much time to figure stuff out)… thanks heaps! your both champs!

#127432
Apr 20, 2008 at 6:10pm

I’m pretty sure that the standard “urn” object is what you’re looking for.

Try [urn 4]. That will do exactly what you’re looking for, AND it’s a standard object. Doesn’t get more efficient than that.

#127433
Apr 20, 2008 at 9:05pm

Quote: swieser1 wrote on Sun, 20 April 2008 20:10
—————————————————-
> I’m pretty sure that the standard “urn” object is what you’re looking for.
>
> Try [urn 4]. That will do exactly what you’re looking for, AND it’s a standard object. Doesn’t get more efficient than that.
—————————————————-

Arguable on two points.

With urn you have to explicitly send a clear message when the urn runs through its contents. Lp.ernie automatically “refills” its urn without requiring an explicit message.

Secondly, a solution with urn would require an [uzi 4] rather than simply banging lp.crabelms.

Proof in the pudding: the lp.crabelms solution was the shortest posted in this thread.

Finally, crabelms uses an industrial-strength RNG. Urn may be assumed to be using the linear congruence implementation from _Numerical Recipes_ used for the other random objects in the factory Max set. If that’s good enough for your purposes, fine. But the Numerical Recipes algorithm is known to have problems if you are generating large numbers of random values.

There is a time and place for standard objects, but there are some things that can be done more efficiently with a well-crafted 3PO.

#127434

You must be logged in to reply to this topic.