php - Controlling likelyhood of randomly generated numbers -
if wanted random number between 1 , 3 $n = mt_rand(1,3).
there 33% chance $n = 1, 33% chance it's 2, , 33% chance it's 3.
what if want create more hard 3 1?
say want 50% chance 1 drawn, 30% chance 2 drawn , 20% chance 3 drawn?
i need scalable solution possible range vary between 1-3 , 1-100, in general i'd lower numbers drawn more higher ones.
how can accomplish this?
this maths.
in illustration chose random number between 0 , 99.
values returned between 0 49 - phone call 1 values returned between 50 - 69 - phone call 2 values returned between 70 - 99 - phone call 3
simple if statement or populate array distribution required
php random dice
No comments:
Post a Comment