Simplify random.Int64 usage with generics
This commit is contained in:
@@ -3,9 +3,11 @@ package random
|
||||
import (
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
|
||||
"golang.org/x/exp/constraints"
|
||||
)
|
||||
|
||||
func Int64(max int64) int64 {
|
||||
rnd, _ := rand.Int(rand.Reader, big.NewInt(max))
|
||||
func Int64[T constraints.Integer](max T) int64 {
|
||||
rnd, _ := rand.Int(rand.Reader, big.NewInt(int64(max)))
|
||||
return rnd.Int64()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user