, , . , , f(0) = 0 f(1) = 1. f(x) = x^2.
- , 0, :
numbers = ceil(max * f(rand()))
ceil - , max - , , f() - , , rand() - . , 1 max, 0 max.
, :

, , .. (max * f (x)) " " 10 "".
, f(x). , - . f(x) - , , , . , f(x) e^x, .
, !
:
public int weightedRandom(int max, Random rand) {
return Math.ceil(((double) max) * Math.pow(rand.nextDouble(), 2));
}
java- , max == 10:
2.0, 6.0, 8.0, 3.0, 2.0, 2.0, 1.0, 1.0, 1.0, 1.0, 7.0, 1.0, 4.0, 1.0, 1.0, 6.0, 8.0, 9.0, 7.0, 5.0