rascle Posted March 3, 2009 Share Posted March 3, 2009 Hi I am creating an online game and i want there to be an $value which is a percentage so lets say 70% and then i want $random number to generate a number that is likely according to the percentage so if the percentage is 70% then $random would more likely to be yes than no. If $value was 30% then $random would more likely to be no than yes and so on and so forth! I know that you could probaly do that using arrays but the only way i could think of doing it would take a long time. Also in the code please bear in mind that $value is dependant on whether the player has a certain objects or whatever. Thanks Rhys Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 3, 2009 Share Posted March 3, 2009 off the top of my head...this should work <?php $chance = 70; if(rand(0,100) <= $chance){ print "Yes"; }else{ print "No"; } ?> edit: That will give you "Yes" 70% of the time Quote Link to comment Share on other sites More sharing options...
rascle Posted March 4, 2009 Author Share Posted March 4, 2009 Thank You I would never of though of doing that ! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.