[chuck-users] Coin in Chuck

Mark Cerqueira mark.cerqueira at gmail.com
Sat Aug 18 22:13:00 EDT 2012


You could do something like this:

// generate a random float between 0.0 and 1.0 and compare its value to the percentage you would like doSomething() to be triggered
if ( Std.rand2f(0.0, 1.0) < 0.20 )
{
    // the code in here has a 20% chance of executing
    doSomething();
}

This is likely what's going on behind the scenes in the coin method in SC.

Hope that helps! :)

mc

On Aug 18, 2012, at 6:55 PM, ronni montoya wrote:

> Hi , in supercollider there is a number method called coin.
> It just gives you back true or false based on probabilities.
> 
> 
> For example:
> 
> 
> 0.2.coin;  ------------->  this means   20 % chance for true.
> 
> So if i do :
> 
> 	if(0.2.coin,{
> 		
> 		doSomething();
> 
> 	});
> 
> 
> The function is gonna have 20% change to be called each time i run that code.
> 
> 
> Is there is something like this in chuck?
> 
> 
> 
> cheers.
> 
> 
> R.
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20120818/95a02cae/attachment.html>


More information about the chuck-users mailing list