Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't set min and max? #3

Open
issmile opened this issue Apr 22, 2018 · 1 comment
Open

can't set min and max? #3

issmile opened this issue Apr 22, 2018 · 1 comment
Labels

Comments

@issmile
Copy link

issmile commented Apr 22, 2018

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?

@bramp
Copy link
Owner

bramp commented Apr 22, 2018

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;
}

@bramp bramp added the question label Apr 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants