# I would like to make a simple arrays for random drum sequencer

Hi, I have a question about making a random IDM drum sequencer.
The main idea is to generate 4 bar array with duration; it plays around 16 bars.
And after that, regenerate the 4 bars with array(duration).

my Idea to make an array, set duration as [0.5, 0.125, 0.25, 1] as the array, choose a number till the total sum of reaching to 4, and loop four times

and it reaches to 16, regenerate the duration array.

I think the “for” iteration loop can handle this issue, but I think It has a more easy way to handle this idea.

does anyone know the easy and elegant ways in supercollider?

``````(
~func = {
arg bar_len = 4;
var durations = [0.5, 0.25, 0.125];
var sequence = [];
var sum = 0;
var next = 0;

(sum < bar_len).while {
var next = durations.choose;
sum = sum + next;
//sequence;
// next = next +1;
};

// sum.postln;
};
)
``````

this is my idea, do you think it works retrun th values of array?

and error message of the code

ERROR: While was called with a fixed (unchanging) Boolean as the condition. Please supply a Function instead.

While loops have to have a function for both the test and body. All you need to do now is either clip the last duration or remove durations greater than `bar_len - sum` from the array on each iteration.

``````(
~func = {
arg bar_len = 4;
var durations = [0.5, 0.25, 0.125];
var sequence = [];
var sum = 0;
var next = 0;

{sum < bar_len}.while {
var next = durations.choose;
sum = sum + next;
};

sequence;
};
)
``````
1 Like

A couple of other ideas could be stolen from Pconst:

``````(
~func = {
arg bar_len = 4, durations = ([0.5, 0.25, 0.125]), tolerance = 0.001;
var sequence = [];
var sum = 0, temp;
var next = 0;

while {
next = durations.choose;
temp = sum + next;
bar_len - temp > tolerance
} {
sum = temp;
};
};
)
``````

(Untested… EDIT: Now tested and fixed.)

Or just use Pconst:

``````Pconst(4, Prand([0.5, 0.25, 0.125], inf)).asStream.all
``````

hjh

1 Like