FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free 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
Related topics
New Xbox has chance to be No. 1, Gates says
Xbox 360 Projected To Outpace Playstation
Ladder to Success
We took a chance...
Wag The Dog my best film
All About WoW
When Jesus was born...
Why are we not going into outer space?
Megaman Phoenix
Would You Help A Stranger?
Atheist pastor keeps job because 15% of pastors are atheist
How to get to success in the study
Louis CK web-published special a success
25 Myths About Christianity
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

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