signal.automatique at gmail.com
Fri Sep 3 12:04:34 EDT 2010
2010/9/3 Mark Cerqueira <mark.cerqueira at gmail.com>
> You can use rand2f to do this....
> float sampleRate;
> if (std.rand2f(0.0, 1.0) < 0.5)
> 1.0 => sampleRate;
> 1.5 => sampleRate;
Mark is right, his code is clean, readable and correct. It could also easily
be tweaked to change the distribution.... And yet I'd still be tempted to do
1 + (.5 * maybe) => float sampleRate;
Generally "maybe" is my first port of call if I want to quickly and randomly
choose between two options;
if (maybe) do_stuff();
Take Mark's option for long term projects that you will need to get back to
or collaborate on. Pick my first option when livecoding as it's short to
type and audiences like "maybe" as a word. My second expample might be
closest to the PD object that you are missing. "maybe" resolves to "true" or
"false" ("1"(int) and "0" (int) in ChucK) with 50/50 chance at each call.
Practically speaking it's completely equivalent to;
However that, unlike Mark's example, can't be tuned in case you later decide
you need a 25/75 distribution instead.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the chuck-users