# Repeating Random Loops?

Hi! I’ve been working with lots of samples lately and I came across a question.

If I have a sample that’s being sliced and reordered randomly inside a loop, is there a way I can make that random order play let’s say 4 times, and then repeat that same exact randomly ordered loop?

For example if the output of a random loop was 1, 3, 5, 4, 2, 7, 8, 4, 6 etc., but I wanted my loop to play the first 4 results over and over => [1, 3, 5, 4] [1, 3, 5, 4] [1, 3, 5, 4] etc., how would I do that?

Ideally I’d love to know how to do this within the sample slicer, i.e. repeating something in this loop:

``````live_loop :sampleslicer, sync: :met1 do
am = 2
c = 130
r = [0.8, 0.4].choose
slice = rand_i(8*2)
slice_size = 0.125/2
s = slice * slice_size
f = s + slice_size
sample :ambi_choir, start: s, finish: f, amp: am, cutoff: c, rate: r, pan: [-0.5, 0.5].choose
sleep 0.5
end
``````

Hi there,

perhaps combining iteration (`n.times`) with `use_random_seed` might help you here?

For example:

``````live_loop :sampleslicer, sync: :met1 do
use_random_seed 3000
4.times do
am = 2
c = 130
r = [0.8, 0.4].choose
slice = rand_i(8*2)
slice_size = 0.125/2
s = slice * slice_size
f = s + slice_size
sample :ambi_choir, start: s, finish: f, amp: am, cutoff: c, rate: r, pan: [-0.5, 0.5].choose
sleep 0.5
end
end
``````

You can then play around with changing the value passed to `use_random_seed` either in production time or live during a performance. This is a technique I use a lot.

Also, whilst slicing a sample manually like you’re doing clearly works and gives you a lot of control, it’s often simpler to use the `slice:` opt along with `num_slices:` which will define how many equally lengthen slices you’d like your sample divided into. There’s also the `onset:` opt which will do automatic feature detection on the sample and extract the 'percussive` elements of the sample and let you index those with a simple number.

Let me know if this helps or if you have any further questions!

1 Like

THANK YOU!! This is exactly what I needed, appreciate it!!!

1 Like