Ah! so simple!
Then my code could be simpler:
(
SynthDef(\randSynth, { |out=0|
var num, freqs, relTimes, relTimesSorted, envs, sig;
num = 12;
freqs = Rand(31, 63).poll(0).midicps * (1.. num);
relTimes = Rand(1, 5) / (1.. num);
// relTimes = Rand(1, 5) / (1.. num) * (Rand(0.9, 1.1)!num);
// relTimes = Rand(1, 5) / (1.. num).sqrt;
// relTimes = Rand(1, 5) / (1.. num).exp;
envs = Env.perc(0.01, relTimes.poll(0)).kr;
FreeSelf.kr(envs.sum <= 0);
sig = SinOsc.ar(freqs) * envs / num;
sig = sig.sum;
Out.ar(out, sig)
}).add
)
Synth(\randSynth)
It would be nice if { Rand(1, 5.0 } ! 12 could be sorted as asked here: Is it possible to sort the output values of Ugen arrays by output value? - #3 by prko