[SIZE=2]Hi all,

A question for all you math experts out there…

how do you make a function that is possibe according to a %

eg:for a stat system,there is a 60% chance to do -2 the enemy,

how do you hake him do that???

Thanks -a-lot!

[/SIZE]

It’s simple.

[AS]

function f60(){

// 60 % chance of getting called

}

var nChance:Number = random(100)

if(nChance<60){

f60 not called

f60();

}else{

```
f60 not called
```

}

[/AS]

thank you!

I’d consider revising it just to eliminate the depricated method call…

```
executeOnChance( 0.6, sayHello );
function sayHello():Void
{
trace("Hello");
}
// chance as a value from 0-1, ex: 50% = 0.5
function executeOnChance( chance:Number, method:Function ):Void
{
var value:Number = Math.random();
if (value < chance) method();
}
```

This makes the idea a little more reusable…

TakeCare

_Michael

EDIT:\ Innapropriate use of the ternary operator