Non-uniform random distribution: How do I get a random between 100 and 180 that is on average close to 120? (like in a Gaussian distribution) Presume I have the following case:


int value a
int value b, for which a &lt; b
int value i, for which a &lt;= i &lt; b
I need an int value x, for which a &lt;= x &lt; b, randomly chosen, according to a non-uniform distribution: the distribution should follow a bell curve which is centered around i.


In Java, I have the following methods available on java.util.Random:


nextInt(int m): int between 0 and m
nextDouble(): double between 0.0 and 1.0
nextGaussian(): double between -Infinity and +Infinity, usually close to 0.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).
Your problem is rather vague: "bell curve" and "centered around i" are not well defined.

One possible recipe is to generate a truncated gaussian: define s= min(b-i,i-a)/c where c is a free parameter (suggested values:  [1,3] range), generate a gaussian with mean i and standard deviation s  - and round it to the nearest integer. If the value falls outside the [a,b] range, try again.

Related.