java - Random but most likely 1 float -
i want randomize float
- there 95% chance 1
- there 0.01% chance < 0.1 or > 1.9
- it never becomes 0 or 2
is possible using random.nextfloat()
several times example?
a visual illustration of probability:
you need find function f such that:
f continuous , increasing on [0, 1]
f(0) > 0 , f(1) < 2
f(0.01) >= 0.1 , f(0.99) <= 1.9
f(x) "about 1" 0.025 <= x <= 0.975
and take f(random.nextdouble())
for example, math.tan(3*(x-0.5))/14.11
fits this, expression i'd use:
math.tan(3*(random.nextdouble()-0.5))/14.11
the probability distributed as:
Comments
Post a Comment