# Repeating Random Patterns with Same Values on Each Repeat?

Apologies, I can’t find this in the documentation or in the tutorials on patterns and I’m sure this is a really basic question.

Which Pbind allows you to take a random sequence and have it repeat x times without choosing new values on repeat? I want it to choose random values at the beginning and then keep them. I have:

~dur = Pseq([
Prand([
Pseq([1/2, 1/2]),
Pseq([1/4, 1/4, 1/2]),
Pseq([1/2, 1/4, 1/4]),
Pseq([1/2, Rest(1/2)]),
]),

Pseq([Rest(1/2), 1/4, 1/4]),

Prand([
Pseq([1/2, 1/2]),
Pseq([1/2, Rest(1/2)]),
]),
Prand([
Pseq([1/4], 4),
Pseq([1/3], 3),
]),
]).asStream;

and I want that outer Pseq to repeat itself as it was originally so only choose random values the first time.

I swear I remember a pattern being able to do this but I can’t find it on the forum or in the help files.

Or do I need to use a routine for this?

You could specify the number of repeats in the inner Pseqs:

(
~repeats = inf;
~dur = Prand([
Pseq([1/2, 1/2], ~repeats),
Pseq([1/4, 1/4, 1/2], ~repeats),
Pseq([1/2, 1/4, 1/4], ~repeats),
Pseq([1/2, Rest(1/2)], ~repeats),
])
)

Or keep your original code and put it inside Pseed:

(
~seed = 123;
~repeats = inf;
~dur = Pseed(
Pn(~seed, ~repeats),
Prand([
Pseq([1/2, 1/2]),
Pseq([1/4, 1/4, 1/2]),
Pseq([1/2, 1/4, 1/4]),
Pseq([1/2, Rest(1/2)]),
])
);
)

Maybe I don’t understand what you’re trying to achieve, but would something like this do what you’d like ?

~dur = Pseq([
[1/2, 1/2],
[1/4, 1/4, 1/2],
[1/2, 1/4, 1/4],
[1/2, Rest(1/2)],
].choose);
1 Like

Maybe you were thinking of Pshuf?
Pshuf | SuperCollider 3.12.2 Help

Best,
Paul

1 Like

I should’ve put the rest of the code, oops.

~dur = Pseq([
Prand([
Pseq([1/2, 1/2]),
Pseq([1/4, 1/4, 1/2]),
Pseq([1/2, 1/4, 1/4]),
Pseq([1/2, Rest(1/2)]),
]),

Pseq([Rest(1/2), 1/4, 1/4]),

Prand([
Pseq([1/2, 1/2]),
Pseq([1/2, Rest(1/2)]),
]),
Prand([
Pseq([1/4], 4),
Pseq([1/3], 3),
]),
]).asStream;

So I want it to choose random values but repeat them. So maybe it chooses the first Pseq in each list, I want it to always play the first Pseq on each step on that particular evaluation.

I.e. if I end up with

Pseq([1/2, 1/2]),
Pseq([Rest(1/2), 1/4, 1/4]),
Pseq([1/2, 1/2]),
Pseq([1/4], 4),

I want that to repeat and the pattern not choose more random values until it’s reevaluated. Does that make more sense?

Not Pshuf. Sorry my original post was not very clear. I’m trying to get a randomly generated pattern to repeat itself infinitely, like turning a Turing Machine all the way to the right.

Yes, this is it! Not sure how you managed to come up with that with all of the missing info from my original post but yeah that’s it. Thanks for reading my mind

1 Like