Marcel1993 Posted December 24, 2010 Share Posted December 24, 2010 Hey guys, I don't know what to do. I've got a script used for gamble: $gamble_rand = rand($number_of_tickets,$gamble_chance); if($gamble_chance == $gamble_rand){ If $number_of_tickets is set by 99 and $gamble_chance is set by 100 the chance is 1:100 that the If-Clause is not true. But it seems to me that PHP is making its on "random". Independent of the values PHP is interpreting that 20 times of 100 times the correct logic is false... If $number_of_tickets is set by 1 there's no big different. Its just a little bit less, but not the chance that it has to be. Thanks for helping and Merry Christmas :-) Quote Link to comment https://forums.phpfreaks.com/topic/222556-trouble-with-rand-in-if-clause/ Share on other sites More sharing options...
parino_esquilado Posted December 24, 2010 Share Posted December 24, 2010 $gamble_rand = rand($number_of_tickets, $gamble_chance); if($gamble_chance == $gamble_rand){ There is a 1/100 chance of the if statement returning true. if $gamble_chance = 1, $gamble_chance = 100. yes -> 92 no -> 9908 0.92% I ran it 10,000 times...see, it works. Are you sure $number_of_tickets <> 20? Quote Link to comment https://forums.phpfreaks.com/topic/222556-trouble-with-rand-in-if-clause/#findComment-1151011 Share on other sites More sharing options...
requinix Posted December 24, 2010 Share Posted December 24, 2010 If $number_of_tickets is set by 99 and $gamble_chance is set by 100 the chance is 1:100 that the If-Clause is not true. Uh, no. There are only two numbers rand() can return in that situation: 99 and 100. Two possibilities. Not 100. Quote Link to comment https://forums.phpfreaks.com/topic/222556-trouble-with-rand-in-if-clause/#findComment-1151017 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.