ActionScript 3 Random Value Generation Determining the success of a "percent chance" operation


Example

If you need to roll for a true or false in an "x% chance" situation, use:

function roll(chance:Number):Boolean {
    return Math.random() >= chance;
}

Used like:

var success:Boolean = roll(0.5); // True 50% of the time.
var again:Boolean = roll(0.25); // True 25% of the time.