<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">You could do something like this:<div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; color: rgb(113, 157, 55); ">// generate a random float between 0.0 and 1.0 and compare its value to the percentage you would like doSomething() to be triggered</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; "><span style="color: #063ff4">if</span> ( Std.rand2f(<span style="color: #df9137">0</span>.<span style="color: #df9137">0</span>, <span style="color: #df9137">1</span>.<span style="color: #df9137">0</span>) < <span style="color: #df9137">0</span>.<span style="color: #df9137">20</span> )</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; ">{</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; color: rgb(113, 157, 55); "><span style="color: #000000">    </span>// the code in here has a 20% chance of executing</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; "><span style="color: #719d37">    </span>doSomething();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; ">}</div></div><div><br></div><div><div>This is likely what's going on behind the scenes in the coin method in SC.</div><div><br></div><div>Hope that helps! :)</div><div><br></div><div>mc</div><div><br><div><div>On Aug 18, 2012, at 6:55 PM, ronni montoya wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Hi , in supercollider there is a number method called coin.<br>It just gives you back true or false based on probabilities.<br><br><br>For example:<br><br><br>0.2.coin;  ------------->  this means   20 % chance for true.<br><br>So if i do :<br><br><span class="Apple-tab-span" style="white-space:pre"> </span>if(0.2.coin,{<br><span class="Apple-tab-span" style="white-space:pre">     </span><span class="Apple-tab-span" style="white-space:pre">    </span><br><span class="Apple-tab-span" style="white-space:pre">  </span><span class="Apple-tab-span" style="white-space:pre">    </span>doSomething();<br><br><span class="Apple-tab-span" style="white-space:pre">  </span>});<br><br><br>The function is gonna have 20% change to be called each time i run that code.<br><br><br>Is there is something like this in chuck?<br><br><br><br>cheers.<br><br><br>R.<br>_______________________________________________<br>chuck-users mailing list<br><a href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</a><br>https://lists.cs.princeton.edu/mailman/listinfo/chuck-users<br></div></blockquote></div><br></div></div></body></html>