Source file src/math/rand/v2/n.go

     1  //go:build goexperiment.genericmethods
     2  
     3  // Copyright 2026 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  package rand
     7  
     8  // N returns a pseudo-random number in the half-open interval [0,n).
     9  // The type parameter Int can be any integer type.
    10  // It panics if n <= 0.
    11  func (r *Rand) N[Int intType](n Int) Int {
    12  	// TODO: See CL 775100,
    13  	// When delete the goexperiment.genericmethods,
    14  	// make this method
    15  	// share the implementation with the global function N
    16  	// and delete this file.
    17  	if n <= 0 {
    18  		panic("invalid argument to N")
    19  	}
    20  	return Int(r.uint64n(uint64(n)))
    21  }
    22  

View as plain text