Kinnati Posted December 13, 2010 Share Posted December 13, 2010 I'd like to figure out how to calculate the chance of success per a certain number of trails by a specific percentage. Essentially, I'm trying to make a calculator for upgrading chances in an MMORPG. The amount of trials is going to be captured via a form and then calculated by a specific percentage. I've already go that dealt with using a switch statement with my form and variables all together... It's just this equation. I have absolutely no clue where to begin. For example, I'd like to do something such as... (.6 * .4 * .2 * .2) * 100 = 0.0096 (rate of success) Then take the number of trials I have (100... 10... 5... or what have you) And calculate the chance of hitting the 0.0096 success rate for those 100 chances. Essentially, with a finished output of something like "Out of 100 tries, your chance of success is X%" I think I need to be using Binomial Distribution, but I've got no idea. The only code out there I'm able to find out there is for Binomial Coefficient (which is helping me none). Thanks for the help in advance. I'm TERRIBLE at math ! ~ Miss Kinnati Quote Link to comment https://forums.phpfreaks.com/topic/221453-binomial-distribution-how-do-i-begin-this/ Share on other sites More sharing options...
sasa Posted December 19, 2010 Share Posted December 19, 2010 chance_for_n_tries = 1 - (1 - chance)^n for example chance is 1-(1-0.0096)^100 Quote Link to comment https://forums.phpfreaks.com/topic/221453-binomial-distribution-how-do-i-begin-this/#findComment-1149155 Share on other sites More sharing options...
Kinnati Posted December 20, 2010 Author Share Posted December 20, 2010 Thanks so much for the reply! I've been trying to get this to work for a week! This code here is nested within a switch statement. I don't bother with creating a function until I get the base working. $trials = 0; // Number of trials $upgradeChance = 0; // Original percent rate of success $rateSuccess = 0; // Total rate of success $rateSuccess = 1 - (1 - $upgradeChance) ^ $trials; echo "Chance of Success: <b>$rateSuccess%</b><br>"; Basically in using your code I'm getting an entire printout of my contents of my switch. Rather amusing I do say... But... I have no idea why it's doing that. I checked the manual and it looks like this is the right usage. However, should I be taking and converting my numbers to binary here? From what I've read this is a bitwise operation, but according to the manual it can be used in this way... No idea. Quote Link to comment https://forums.phpfreaks.com/topic/221453-binomial-distribution-how-do-i-begin-this/#findComment-1149379 Share on other sites More sharing options...
sasa Posted December 20, 2010 Share Posted December 20, 2010 i wrote just pseudo code in pascal notation php code looks like $trials = 2; // Number of trials $upgradeChance = 0.5; // Original percent rate of success 50% $rateSuccess = 0; // Total rate of success is 3 of 4 $rateSuccess = 1 - pow((1 - $upgradeChance), $trials) ; echo "Chance of Success: <b>".$rateSuccess * 100 ."%</b><br>"; Quote Link to comment https://forums.phpfreaks.com/topic/221453-binomial-distribution-how-do-i-begin-this/#findComment-1149429 Share on other sites More sharing options...
Kinnati Posted December 29, 2010 Author Share Posted December 29, 2010 Works elegantly. Thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/221453-binomial-distribution-how-do-i-begin-this/#findComment-1152412 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.