Patterns containing repeated random

Hi list,

I would like to generate a series of values inside a pattern which
contain randomized elements. This series should then be repeated N times
without re-evaluating the randomized elements, and that whole thing
should loop forever.

Putting the above in numbers, I am aiming at something like the
following, with the third number randomized.
1 2 3
1 2 3
1 2 3

1 2 5
1 2 5
1 2 5

1 2 12
1 2 12
1 2 12

…and continuing forever.

I know that in the following line, .rand is only evaluated once.

Pbind(\note, Pseq([6, 6, 12.rand], 4)).play;

And here, .rand is evaluated at every repeat

Pbind(\note, Pseq([6, 6, {12.rand}], 4)).play;

The following attempt will repeat the same random value forever

Pbind(\note, Pn(Pseq([6, 6, 12.rand], 4)))..trace.play; 

and this one will produce a different random value at every repeat

Pbind(\note, Pn(Pseq([6, 6, {12.rand}], 4))).trace.play; 

I hope I am somewhat clear :slight_smile:

Thanks for all suggestions!
best, Peter

This seems to do the trick:

(
var innerRepetitions, outerRepetitions;
innerRepetitions = 3;
outerRepetitions = 5;
Pn(Plazy({Place([[1], [2], 3.rrand(18)!innerRepetitions], innerRepetitions)}), outerRepetitions).asStream.all
)

I guess you can use outerRepetitions = inf to have infinite repeat, but then don’t use it with asStream.all or you will get an infinite loop :smiley:

Ahh I had misunderstood:

Pbind(*[note: Ptuple([1, 12, Pdup(3, Pwhite(3, 18, inf))], inf)]).play