sw0o0sh Posted August 2, 2010 Share Posted August 2, 2010 Hi, I run a gameserver that has it's own type of currency, and I'm making a gamble system where people can wager their "game gold". All they do is bet the amount of gold they wish to bet, and the script does the rest. Say they have a 1 in 15 chance of doubling their wager, is this appropriate (as in, is this really a 1 in 15 chance?). $generated_number = mt_rand(1,15); $selected_number = mt_rand(1,15); if($generated_number == $selected_number) { you won } etc etc Is that really a 1 in 15 chance? I'm not that swell with math, and is there a term for what I'm doing so I could perhaps learn? Quote Link to comment Share on other sites More sharing options...
btherl Posted August 2, 2010 Share Posted August 2, 2010 That looks like 1 in 15 to me. This is also 1 in 15: $selected_number = mt_rand(1,15); if ($selected_number == 1) { you won } 1 in 15 is not very good odds if they lose their entire wager when they lose. You could do something like 45 out of 100: $selected_number = mt_rand(1,100); if ($selected_number <= 45) { you won } Then they will generally lose in the long run, but it's also likely for them to have lucky streaks. Quote Link to comment Share on other sites More sharing options...
sw0o0sh Posted August 2, 2010 Author Share Posted August 2, 2010 That looks like 1 in 15 to me. This is also 1 in 15: $selected_number = mt_rand(1,15); if ($selected_number == 1) { you won } 1 in 15 is not very good odds if they lose their entire wager when they lose. You could do something like 45 out of 100: $selected_number = mt_rand(1,100); if ($selected_number <= 45) { you won } Then they will generally lose in the long run, but it's also likely for them to have lucky streaks. Thanks, that first way seems a bit more efficient. One last question though, say they have a 1 in 10 chance to win their bet x 2, 1 in 100 chance to win their bet x 10, 1 in 1000 chance to win their bet x 100, etc etc, How would I figure there total chance of winning anything (as in, any 3 of those possibilities)? Quote Link to comment Share on other sites More sharing options...
btherl Posted August 2, 2010 Share Posted August 2, 2010 I wouldn't worry about efficiency here. More important is how clear the code is. If you want to calculate the probability of any of a number of random events happening, the formula is: Let P1 = 0.1, P2 = 0.01, P3 = 0.001 (probabilities of winning x2, x10, x100). The chance of NOT getting ALL of those is (1-P1) * (1-P2) * (1-P3). The inverse of that is the chance of getting AT LEAST ONE of those, 1 - (1-P1) * (1-P2) * (1-P3) = 1 - (0.890109) = 0.109891 That's just under 11% That doesn't take into account how much they win each time though. Calculating their likely winnings is another matter altogether, complicated by the fact that their winnings on the next round are affected by how much they won/lost the previous round. 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.