Documentation
¶
Index ¶
- Constants
- func Digits(length int, hasLeadingZero ...bool) string
- func Duration(min, max time.Duration) time.Duration
- func ExpFloat64() float64
- func Float32() float32
- func Float32R(min, max float32) float32
- func Float64() float64
- func Float64R(min, max float64) float64
- func Int() int
- func Int32() int32
- func Int32N(n int32) int32
- func Int32R(min, max int32) int32
- func Int64N(n int64) int64
- func Int64R(min, max int64) int64
- func IntN(n int) int
- func IntR(min, max int) int
- func Letters(length int) string
- func Lucky(probability float64, base ...float64) bool
- func NormFloat64() float64
- func Perm(n int) []int
- func Shuffle[T any](list []T)
- func Str(seed string, length int) string
- func Symbols(length int) string
- func Uint() uint
- func Uint32() uint32
- func Uint32N(n uint32) uint32
- func Uint64() uint64
- func Uint64N(n uint64) uint64
- func UintN(n uint) uint
- func Weight[T any](fn func(v T) float64, list ...T) (int, T, bool)
Constants ¶
const ( LetterSeed = rand.LetterSeed // Letters in both upper and lower case LetterLowerSeed = rand.LetterLowerSeed // Lower-case letters LetterUpperSeed = rand.LetterUpperSeed // Upper-case letters DigitSeed = rand.DigitSeed // Digits DigitWithoutZeroSeed = rand.DigitWithoutZeroSeed // Digits without zero SymbolSeed = rand.SymbolSeed // Special symbols )
Variables ¶
This section is empty.
Functions ¶
func Digits ¶
Digits returns a string of the given length made of digits. The optional hasLeadingZero reports whether the string may start with zero.
func ExpFloat64 ¶ added in v2.6.0
func ExpFloat64() float64
ExpFloat64 returns a 64-bit float drawn from an exponential distribution with rate parameter (lambda) 1 and mean 1.
func Int32N ¶ added in v2.6.0
Int32N returns a non-negative pseudo-random 32-bit integer in [0, n). n must be greater than 0.
func Int64N ¶ added in v2.6.0
Int64N returns a non-negative pseudo-random 64-bit integer in [0, n). n must be greater than 0.
func IntN ¶ added in v2.6.0
IntN returns a non-negative pseudo-random integer in [0, n). n must be greater than 0.
func Lucky ¶
Lucky reports whether a lucky draw with the given probability hits. The optional base is the probability denominator and defaults to 100.
func NormFloat64 ¶ added in v2.6.0
func NormFloat64() float64
NormFloat64 returns a 64-bit float drawn from the standard normal distribution, with mean 0 and standard deviation 1.
func Shuffle ¶ added in v2.1.0
func Shuffle[T any](list []T)
Shuffle randomly reorders list in place.
func Uint32 ¶ added in v2.6.0
func Uint32() uint32
Uint32 returns a pseudo-random 32-bit unsigned integer.
func Uint32N ¶ added in v2.6.0
Uint32N returns a non-negative pseudo-random 32-bit unsigned integer in [0, n). n must be greater than 0.
func Uint64 ¶ added in v2.6.0
func Uint64() uint64
Uint64 returns a pseudo-random 64-bit unsigned integer.
func Uint64N ¶ added in v2.6.0
Uint64N returns a non-negative pseudo-random 64-bit unsigned integer in [0, n). n must be greater than 0.
func UintN ¶ added in v2.6.0
UintN returns a non-negative pseudo-random unsigned integer in [0, n). n must be greater than 0.
func Weight ¶
Weight performs a weighted random selection over list, where fn returns the weight of an item. It returns false when the total weight is invalid (<= 0).
On success it returns the index of the selected item, the item itself and true. When nothing is selected it returns -1, the zero value of T and false.
Types ¶
This section is empty.