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

math/rand: Intn(<=0) returns unexpected result #2892

Closed
pjweinb opened this issue Feb 6, 2012 · 3 comments
Closed

math/rand: Intn(<=0) returns unexpected result #2892

pjweinb opened this issue Feb 6, 2012 · 3 comments
Assignees
Milestone

Comments

@pjweinb
Copy link

@pjweinb pjweinb commented Feb 6, 2012

If the interval [0, n) is empty, math.Intn(n) returns 0, which is not in the interval. 
I'd prefer a panic("math.Intn(non-positive integer)"), but even changing the
documentation would be better.  E.g., "If the interval is empty the result is not
defined, or there might be a panic."
@rsc
Copy link
Contributor

@rsc rsc commented Feb 6, 2012

Comment 1:

Labels changed: added priority-go1, removed priority-triage.

Owner changed to builder@golang.org.

Status changed to Accepted.

@robpike
Copy link
Contributor

@robpike robpike commented Feb 17, 2012

Comment 3:

Owner changed to @robpike.

Status changed to Started.

@robpike
Copy link
Contributor

@robpike robpike commented Feb 17, 2012

Comment 4:

This issue was closed by revision 7d1c532.

Status changed to Fixed.

@pjweinb pjweinb added fixed labels Feb 17, 2012
@rsc rsc added this to the Go1 milestone Apr 10, 2015
@rsc rsc removed the priority-go1 label Apr 10, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.