2010/9/3 Mark Cerqueira <mark.cerqueira@gmail.com>
Tim,
You can use rand2f to do this....

float sampleRate;

if (std.rand2f(0.0, 1.0) < 0.5)
    1.0 => sampleRate;
else
    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 this;

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();
else do_things();

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;

 Std.rand2(0,1)

However that, unlike Mark's example, can't be tuned in case you later decide you need a 25/75 distribution instead.

Yours,
Kas.