I recommend using the function:
where s and g represent your minimum and maximum values, respectively, R is a random number between 0 and 1 (inclusive) and n is a pre-determined constant. The notation ||x|| represents the nearest integer to x.
An example in PHP 5:
function biasedRandom($min, $max) {
$power = 2;
# lcg_value() returns a random number between 0 and 1
$bias = pow(lcg_value(), $power);
return round($min + ($max-$min) * $bias);
}
In an IPython notebook I ran my function 1000 times each for different powers. It generated this graph, where each value (x-axis) is plotted against the probability of it occurring (y-axis):
The graph shows that as p, the power which we raise the random number to, increases, the 'steepness' of the graph also increases.
That is to say, a higher value of p will make the smallest value, in this case 1, to have a much higher probability of occurring than the highest value, 10. See the green line, where p equals 8.
In the case of the blue line, where p is only equal to 2, the bias is far less extreme, and all numbers are closer in probability.
This animation demonstrates how the probabilities of each value change with different values of p:
I used this python function to generate each of the biased random numbers used as data in all of the following graphs.
These box-plots each show the distribution of 500 values generated by my function, with powers of (from top to bottom) 2, then 2.5 then 4.
The box-plots clearly show that smaller numbers are more common than larger numbers (the medians are all less than 5.5), and that there is a higher density of values towards the lower end of the spectrum. However, one can also see how high values (all the way up to ten) still emerge sometimes.
If we compare the box-plots we can again see that a lower power (the top-most box-plot has the lowest power, in this case 2) leads to a more even spread of values, with high values appearing more frequently and low values appearing less frequently than when using higher powers.
Without rounding the function's final result, we can obtain the following visualisation, which shows clearly the higher density of smaller numbers. Values are plotted as they are obtained by the function.
The above image shows the distribution of results for powers 8, 16 and 32. The layout is intended to represent a number line, with 1 on the far left and 10 on the right.