Random Number Generation Without Numbers Repeating Twice in a Row

May 1, 2008 at 7:06pm

Random Number Generation Without Numbers Repeating Twice in a Row

Hi, I was wondering if anybody had any ideas on random number generation without repeating any 2 numbers twice in a row. Meaning 1,1 cannot happen but 1, 2, 1 can. I have tried messing around with the Urn object which works, but it needs to be cleared after all numbers are output and that creates a small pause before resetting. I am looking for a way to generate continuously random numbers that don’t occur in a row.

I’ve also tried hooking up Random to Change but if random generates a number twice in a row then there is a pause in output.
I’m trying to avoid that.

Any help is greatly appreciated.

Thanks.

#37446
May 1, 2008 at 7:39pm

Have a look at the rtc-lib. Lots of interesting stuff, including anti-
repeat stuff.

http://www.essl.at

Op 1-mei-2008, om 21:06 heeft WPPK het volgende geschreven:

>
> Hi, I was wondering if anybody had any ideas on random number
> generation without repeating any 2 numbers twice in a row. Meaning
> 1,1 cannot happen but 1, 2, 1 can. I have tried messing around
> with the Urn object which works, but it needs to be cleared after
> all numbers are output and that creates a small pause before
> resetting. I am looking for a way to generate continuously random
> numbers that don’t occur in a row.
>
> I’ve also tried hooking up Random to Change but if random
> generates a number twice in a row then there is a pause in output.
> I’m trying to avoid that.
>
> Any help is greatly appreciated.
>
> Thanks.

#129438
May 1, 2008 at 7:51pm

Or you could use 2 urns, like a double buffer.

#129439
May 1, 2008 at 7:55pm

Right!! Thank you. That’ll do it.

#129440
May 1, 2008 at 8:35pm

On May 1, 2008, at 12:06 PM, WPPK wrote:
> Hi, I was wondering if anybody had any ideas on random number
> generation without repeating any 2 numbers twice in a row. Meaning
> 1,1 cannot happen but 1, 2, 1 can. I have tried messing around with
> the Urn object which works, but it needs to be cleared after all
> numbers are output and that creates a small pause before resetting.
> I am looking for a way to generate continuously random numbers that
> don’t occur in a row.

Reseting urn doesn’t cause a pause, in my experience. Here’s an
abstraction, called UrnCounter, which is like a counter that counts a
random pattern. Perhaps you could pull some techniques out if it?

– Pasted Max Patch, click to expand. –

Chris Muir
cbm@well.com

http://www.xfade.com

#129441
May 1, 2008 at 9:16pm

Thanks. I’ll take a look, but the text file seems a bit strange. Is it correct? For Max 5?

#129442
May 1, 2008 at 10:03pm

On May 1, 2008, at 2:16 PM, WPPK wrote:
> Thanks. I’ll take a look, but the text file seems a bit strange. Is
> it correct? For Max 5?

That’s the new (as of 5.0.1) Copy Compressed format.

SImply copy the lines, including the lines:
———-begin_max5_patcher———-
———-end_max5_patcher———-

And do a New From Clipboard in Max.

-C

Chris Muir
cbm@well.com

http://www.xfade.com

This post seems to contain a broken pasted patch. This can happen if you don’t copy the entire “———-begin_max5_patcher———-” or “———–end_max5_patcher———–” for each and every patch you paste; perhaps you missed a preceding or trailing “-” when you copied the patch? Please notify the Cycling 74 web team if you think it is a bug.

#129443
May 2, 2008 at 12:39am

Any chance you can put this in a text that 4.6 will open. I can’t open it.

Thanks.

#129444
May 2, 2008 at 12:46am

Here it is in Max 4, but only because I had an older version. I think that people sticking with Max 4 are going to be orphans before too long.

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P hidden comment 0 412 55 196617 lower left;
#P window linecount 2;
#P comment 2 34 442 196617 Steps through a random pattern between RangeLow and RangeHigh. A bang in NewPattern creates a new random pattern (and reports the seed). Seeds can be passed in through NewPattern.;
#P window linecount 1;
#P newex 318 195 40 196617 t b b i;
#P newex 372 243 27 196617 – 0;
#P newex 318 169 27 196617 – 1;
#P newex 69 366 27 196617 + 1;
#N comlet Seed;
#P outlet 274 397 15 0;
#P comment 289 397 34 196617 Seed;
#P newex 184 104 72 196617 route bang int;
#P comment 313 83 57 196617 Range Low;
#N comlet Range Low;
#P inlet 296 83 15 0;
#P comment 389 83 64 196617 Range High;
#P comment 145 83 35 196617 Reset;
#P comment 85 83 29 196617 Trig;
#P newex 38 182 30 196617 t b b;
#P number 184 156 49 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 184 136 70 196617 random 9999;
#P newex 184 200 85 196617 prepend set seed;
#P newex 130 216 30 196617 t b b;
#P message 184 242 69 196617 seed 5343;
#P newex 69 324 40 196617 urn 52;
#B color 5;
#P message 130 242 37 196617 clear;
#P button 69 242 15 0;
#P comment 200 83 64 196617 NewPattern;
#N comlet Reset;
#P inlet 130 83 15 0;
#N comlet NewPattern;
#P inlet 184 83 15 0;
#N comlet Range High;
#P inlet 372 83 15 0;
#N comlet Trig;
#P inlet 69 83 15 0;
#N comlet Index;
#P outlet 69 397 15 0;
#P comment 84 397 34 196617 Index;
#P window setfont “Sans Serif” 18.;
#P comment 2 6 108 196626 UrnCounter;
#P window setfont “Sans Serif” 9.;
#P comment 110 15 100 196617 Deck Shuffler;
#P connect 29 2 28 1;
#P connect 29 1 28 0;
#P connect 5 0 28 0;
#P connect 27 0 29 0;
#P fasten 21 0 26 1 301 360 91 360;
#P connect 21 0 27 0;
#P fasten 16 0 25 0 189 181 279 181;
#P connect 23 1 14 0;
#P lcolor 7;
#P connect 23 1 25 0;
#P lcolor 7;
#P connect 14 0 12 0;
#P connect 13 1 12 0;
#P connect 29 0 12 0;
#P connect 16 0 14 0;
#P connect 15 0 16 0;
#P connect 23 0 15 0;
#P connect 6 0 23 0;
#P connect 13 0 10 0;
#P connect 7 0 13 0;
#P connect 17 1 13 0;
#P fasten 28 0 11 1 377 318 104 318;
#P connect 26 0 3 0;
#P connect 11 0 26 0;
#P connect 9 0 11 0;
#P connect 12 0 11 0;
#P connect 10 0 11 0;
#P connect 4 0 9 0;
#P connect 17 0 9 0;
#P fasten 11 1 17 0 104 349 28 349 28 176 43 176;
#P window clipboard copycount 32;

#129445
May 2, 2008 at 1:14am

I would also like to point out that in the Max4 examples folder, in
misc-max-trix/notes-and-pitch/random w_o repeat a patch called urn-jb-
help.pat does this. The same patch is in the Max5 examples, in max-
tricks/random_with_no_repeat.

Brad

On 1-May-08, at 6:46 PM, Chris Muir wrote:

>
> Here it is in Max 4, but only because I had an older version. I
> think that people sticking with Max 4 are going to be orphans before
> too long.
>
>
>
>
>
> –
> Chris Muir
> cbm@well.com
> http://www.xfade.com
>
>

#129446

You must be logged in to reply to this topic.