fun int likely(int howLikely) {
for (0 => int i; i < howLikely; i++)
answer || maybe => answer;
return answer;
}
fun int unlikely(int howUnlikely) {
for (0 => int i; i < howUnlikely; i++)
answer && maybe => answer;
return answer;
}
The argument passed makes the function more or less likely to return true (e.g. setting howLikely to 3 results in 93% hits, while setting howUnlikely to 3 results in 6% hits). Again, results will deviate a little over time, but I think that's desired if you're throwing words likely likely, maybe, and unlikely into your ChucK programs.
I'm attaching a file that includes these methods and tests that run these methods several times, printing out the number of hits. Sorry about the copy-and-paste abuse. Below is a transcript of the log the program prints for 100,000 trials using different variations of the above methods.
Best,
mark