Also, in this case, I want to pick up randomly 3 different blocks in the middle of the array and then put them back inside with duplication, which can create cool trance patterns, example
original : [1, 2, 3, 4, 5, 6];
result : [ 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 2, 2, 3, 4, 5, 6, 1, 2, 3. etc...
It works well but this syntax is quite heavy, what is possible to make it more ergonomic and elegant ? Thanks
The code:
(
a = [1, 2, 3, 4, 5, 6];
~minrepeat = 1;
~maxrepeat = 3;
~start_idx = rrand(0, a.size);
~end_idx = rrand(0, a.size);
~dup = rrand(~minrepeat, ~maxrepeat);
~start_idx2 = rrand(0, a.size);
~end_idx2 = rrand(0, a.size);
~dup2 = rrand(~minrepeat, ~maxrepeat);
~start_idx3 = rrand(0, a.size);
~end_idx3 = rrand(0, a.size);
~dup3 = rrand(~minrepeat, ~maxrepeat);
b = a.insert(~start_idx, a.copyRange(~start_idx, ~end_idx)!~dup).flat;
c = a.insert(~start_idx2, a.copyRange(~start_idx2, ~end_idx2)!~dup2).flat;
d = a.insert(~start_idx3, a.copyRange(~start_idx3, ~end_idx3)!~dup3).flat;
e = (b ++ c ++ d).postln;
)