FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

deciding success on percentage chance

 


woodenbrick
I'm making a little online game and there is a part which involves checking different variables and ending up with $percentageChance (some value between 0 and 1).
My question is how do I actually use this value to decide if someone was successful or not. I know it's something probably quite simple but I can't think what.
mathiaus
Try this. It's a little rough and untested but should in (my) theory work Smile

Code:
$choice = mt_rand(0, 100) / 100;
if($choice <= $percentageChance) {
   //WIN
} else {
   //LOSS
}
woodenbrick
It works fine, thanks for your help. Very Happy
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.