Uniform distribution in a small range to generate precise big probability
问题 Currently I'm using a uniform distribution to generate a winning probability. For a probability of let's say 1% I define a winning number 47 then I do a mt_rand(1,100) and if the number is 47 the user win. Which is fine. This work well for small probability like 1/100'000 but when I want a probability of let's say 40% which is 1/0.4 = 2.5 I cannot make mt_rand(1,2.5) I have to do mt_rand(1,2) or mt_rand(1,3) which mean respectively 50% and 33% . How should I do to get a 40% probability? 回答1: