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
The
math/rand/v2package contains a useful genericNfunction:There is no corresponding
rand.Rand.Nmethod, because we didn't have generic methods whenmath/rand/v2was created. With the acceptance of #77273, we can add that method. I propose that we do so (once #77273 is implemented):