Presume I have the following case:
- int value
a
- int value
b
, for whicha < b
- int value i, for which
a <= i < b
- I need an int value
x
, for whicha <= x < b
, randomly chosen, according to a non-uniform distribution: the distribution should follow a bell curve which is centered aroundi
.
In Java, I have the following methods available on java.util.Random
:
nextInt(int m)
: int between0
andm
nextDouble()
: double between0.0
and1.0
nextGaussian()
: double between-Infinity
and+Infinity
, usually close to0.0
.
How do I build such a non-uniform distribution from these building blocks? How do I reliably and efficiently transform nextGaussian()
into nextGaussian(a, b, i)
? The part I am struggling with is to enforce that x is selected between a and b (without doing a trial-and-error).