Skip to content

math/rand/v2: add Rand.N #77853

Description

@neild

The math/rand/v2 package contains a useful generic N function:

// N returns a pseudo-random number in the half-open interval [0,n) from the default Source.
// The type parameter Int can be any integer type.
// It panics if n <= 0.
func N[Int intType](n Int) Int

There is no corresponding rand.Rand.N method, because we didn't have generic methods when math/rand/v2 was created. With the acceptance of #77273, we can add that method. I propose that we do so (once #77273 is implemented):

// N returns a pseudo-random number in the half-open interval [0,n).
// The type parameter Int can be any integer type.
// It panics if n <= 0.
func (r *Rand) N[Int intType](n Int) Int

Metadata

Metadata

Assignees

No one assigned

    Labels

    LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposalProposal-Accepted

    Type

    No type

    Projects

    Status
    Accepted

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions