Prand stream of values repeating

Hi all,

I’d like to change the stream of value a Prand creates only after a number of time it repeats the same value pattern.

E.g. let’s say a Prand creates the following values: 1,2,4,4,3 then these five values repeat four times, only after which the stream of values change let’s say to 2,3,3,4,1 that repeats four times, etc.

I tried to solve this by embedding the Prand((1..4),5) into Pn, Plazy, Pfunc, Pdup. I also tried with writing {(1..4).choose}!5 and then I got stuck as to how to use it as a stream. Pshuf didn’t seem to give the desired result. I was also trying to do something along the lines of Prand.collect but couldn’t wrap my head around how I can collect the values Prand creates 5 times and then use it as a stream of values. In all of these cases there was a missing element in the chain to achieve the above result. I checked forum discussions here but I couldn’t find any relevant thread.

Is there a short and simple way to do this? Or is Prand not even the way to go to achieve this?

Thanks,
cd

ok, I found the solution:

(
p = Pbind(
	\dur, 0.25,
	\scale, Scale.minor,
	\degree, Pn(Plazy({
		Pseq(
			list: Prand((1..4),inf).collect{|i| i }.asStream.nextN(5),
			repeats: 4)
	})).trace
).play;
)
p.stop;

In the ddwPatterns quark, Pscratch can also do it:

(
var clumpToRepeat = 5;
var numRepeats = 4;
Pscratch(
	Pseries(0, 1, inf),
	Pseq([
		1,
		Pseq([Pn(1, clumpToRepeat - 1), 1 - clumpToRepeat], numRepeats - 1),
		Pn(1, clumpToRepeat - 1)
	], inf)
)
.asStream.nextN(40)
)

// this proves that it repeats the last 5 values,
// then moves to the next 5
-> [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9]

// go back to the random generator, it still holds
(
var clumpToRepeat = 5;
var numRepeats = 4;
Pscratch(
	Prand((1..4), inf),
	Pseq([
		1,
		Pseq([Pn(1, clumpToRepeat - 1), 1 - clumpToRepeat], numRepeats - 1),
		Pn(1, clumpToRepeat - 1)
	], inf)
)
.asStream.nextN(40)
)

-> [2, 3, 4, 2, 2, 2, 3, 4, 2, 2, 2, 3, 4, 2, 2, 2, 3, 4, 2, 2, 1, 4, 1, 2, 1, 1, 4, 1, 2, 1, 1, 4, 1, 2, 1, 1, 4, 1, 2, 1]

hjh