Skip to content

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

@pjweinb

Description

@pjweinb
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."

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions