[sharing] urn with gen~

bertrandfraysse's icon

I ended up making a gen~ version of the max object urn, generating non repeating integer random numbers.
If anyone find a simpler way of doing it, I'm interested.

Max Patch
Copy patch and select New From Clipboard in Max.

bertrandfraysse's icon

the "error avoider" can add some variations to rhythm based things...

Max Patch
Copy patch and select New From Clipboard in Max.

have fun.

Graham Wakefield's icon

How's the following. Only limitation is that the maximum urn size is determined by the internal [data] object.

Of course you could use a buffer~ instead, and that way make the urn data public. Maybe even use the buffer dim as the urn size.

Max Patch
Copy patch and select New From Clipboard in Max.

all's icon

Hello,

Thank you for your great help !!!
Have a nice day.
My best,
Alex

bertrandfraysse's icon

Thank you for sharing graham, this is great.

bertrandfraysse's icon

Hi everyone, I'm coming back to this !

I'd be interested in a variation on this concept, but unfortunately all I tried failed.


I would like that when resetting the urn, it would not have the possibility to produce a repetition with the previous value.

ex with 3 different values

trig 1 : 2 then trig2 : 0 then trig3 : 1 it restarts and it may do trig 1 : 1 then trig2 : 0 then trig3 : 2

so the trig 3 of the previous cycle is the same as the first trig of the next cycle.

I hope it's clear.

I tried to store the "previous value" and use a while loop with a new value without succes.

Thanks everyone, I think it could be a useful tool, even more musical than this urn which is already nicer than random.

bertrandfraysse's icon

ok, I found this solution, it's a bit brutal, but it works. I'm sure there's a smarter way with a loop or something. Anyway, welcome to the TRUE urn.

Max Patch
Copy patch and select New From Clipboard in Max.

Graham Wakefield's icon

A testament to the value of urn that it is worth coming back to 10 years later!

I also realized that the urn emulation in the GO book has a similar problem: the last step of one loop can end up being the 1st step of the next loop. The urn in the GO book works in a different way: on each step, swap the value at the current step with a value somewhere later in the data. So, the fix was fairly simple: on the 1st step, prevent it from swapping with the final step. I'll add that to the GO package download for the next update. In the meantime, here's the codebox in full, and patcher attached.

Data deck(32);
Param len(8, min=2, max=32);
Param loop(0.8, min=0, max=1);
History step, reset, output; 

// trigger on a rising edge
trig = change(in1 > 0) > 0; 
reset = change(in2 > 0) > 0 || reset; 

// rebuild the decl as [0, 1, 2, .. len-1]
if (change(len)) {
	for (i=0; i<dim(deck); i+=1) {
		poke(deck, i, i);
	}
}
	
if (trig) {
	// reset or move to next step:
	step = reset ? 0 : (step + 1) % len;
	reset = 0;
	
	// how many items remain in the list?
	remain = len-step;
    // special case: on step 0, prevent us from using 
    // the previous loop's final step
    if (step == 0) { remain -= 1; }
	
	// pick another item to swap with?
	looping = abs(noise()) < loop;
	if (!looping) { 
        swap = step + floor(abs(noise())*remain);
        // read them & swap them:
		a = peek(deck, swap);
		b = peek(deck, step);
		poke(deck, a, step);
		poke(deck, b, swap);
		// output the one we picked
		output = a;	
	} else {
		output = peek(deck, step);
	}
}

out1 = output; 
out2 = step;
Max Patch
Copy patch and select New From Clipboard in Max.

MakePatchesNotWar's icon

Graham, as always thanks for invaluable information but i have to ask though. Is there really no other way to obtain the GO book? I'd love to have it but i refuse to support that bozo guy...

bertrandfraysse's icon

I hoped you would shime in, Graham. Thank you for sharing this clever and concise version. The looping option is great too !