I’m trying to design an odds system that goes from 1-100, however it also uses 0-1 for rarer odds.
I was told I should use a floating point format, but I don’t know that.
Basically I have..
if (mt_rand(1,1000)/100 == $odds) {} else if (mt_rand(1,100) == $odds) {}
however that only yields the same probability.
I looked up floating point format in the PHP manual, but the answers there couldn’t help me.
See Odds to understand how to convert your odds to a probability. If you have odds of
4:1then there is a1/5 == 0.2probability of the event. If your odds are.2:1then there is a5/6(about .833) probability of the event happening. In general, if the odds arem:nagainst then the probability isn/(m+n).Now, if you want to simulate whether an event occurs or not, you need to get a random floating point number between
0and1then check if this is less than the probability of the event. You can use something likemt_rand(0,1000)/1000to get a random number between0and1.Examples: