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 Link to comment https://forums.phpfreaks.com/topic/147795-solved-random-percentage/ 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 Link to comment https://forums.phpfreaks.com/topic/147795-solved-random-percentage/#findComment-775796 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 ! Link to comment https://forums.phpfreaks.com/topic/147795-solved-random-percentage/#findComment-776508 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.