Add function number.RandomInt64
This commit is contained in:
+11
-1
@@ -1,6 +1,11 @@
|
||||
package number
|
||||
|
||||
import "golang.org/x/exp/constraints"
|
||||
import (
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
|
||||
"golang.org/x/exp/constraints"
|
||||
)
|
||||
|
||||
func Min[T constraints.Ordered](vs ...T) T {
|
||||
if len(vs) == 0 {
|
||||
@@ -29,3 +34,8 @@ func Max[T constraints.Ordered](vs ...T) T {
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
func RandomInt64(max int64) int64 {
|
||||
rnd, _ := rand.Int(rand.Reader, big.NewInt(max))
|
||||
return rnd.Int64()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user