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:

a visual illustration of probability

you need find function f such that:

  1. f continuous , increasing on [0, 1]

  2. f(0) > 0 , f(1) < 2

  3. f(0.01) >= 0.1 , f(0.99) <= 1.9

  4. 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:

wolfram cloud session


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -