Hello,
I still don't understand how to randomize numbers fairly. Let's say I want fair numbers 0,1,2,3,4, and 5, but I'm having trouble getting number 5, it's almost impossible to get this number. I mean the last number.
The code is int(random(0,5))
Is there any other way to randomize numbers fairly?
Thank you.
round(random(0,5))
Hi.
It's better to round up, so the distribution will be more even, in fact they will replace the
choose(0,1,2,3,4,5) = round(random(0,5))
but good random is an ancient halivar.
Hi Igortyhon,
Thanks
It's better now.
igortyhon
No, that’s not correct. The correct expression is int(random(0,6))
choose(0,1,2,3,4,5) = int(random(0,6))
Using round(random(0,5)) skews the distribution — both the lowest and highest numbers in the range will have a 50% lower chance of appearing compared to the others.
See this demo:
dropbox.com/scl/fi/kpnbq43gc6786r9blg7xn/RandomDemo.capx
dop2000
I agree the “int” method works better, by the way the “floor” method also works well.
But in order to get good figures for both methods “int” and “floor” we have slightly extended the range of generation to get the right sample, if we do the same for “round”, this method also shows itself well.
Here is an example.
fex.net/en/s/c2tlmek
Develop games in your browser. Powerful, performant & highly capable.
if we do the same for “round”, this method also shows itself well.
Yes. But floor(random(0,6)) is easier to type and understand than round(random(-0.5,5.5))