Say, if I wanted to generate an unbiased random number between min
and max
, I'd do:
var rand = function(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
But what if I want to generate a random number between min
and max
but more biased towards a value N
between min
and max
to a degree D
? It's best to illustrate it with a probability curve:
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…