prob.js
prob.js copied to clipboard
can't set min and max?
sorry I am chinese ,not good at english,may be read not good
rob.normal(0, 1.0) see the doc ,I have see min and max ,but when I set min = 1 max = 8 ,it seens do not work, emm........it is can't set? need make it self ? only for read?
Yes, min and max are only for reading. They tell you the minimum and maximum value the distribution may produce.
There is no way to truely generate a normal distribution who values are bound by a min and max. The best you can do is to either discard the number if outside the range, or clamp the value. For example
var r = Prob.normal(0, 1.0);
// Discard and pick another
x = r();
while (x < 1 || x > 8) {
x = r();
}
or
var r = Prob.normal(0, 1.0);
// Clamp the value
x = r();
if (x < 1) {
x = 1;
} else if (x > 8) {
x = 8;
}