Documentation
¶
Index ¶
- Constants
- type PseudoRandom
- func (*PseudoRandom) ExpFloat64() float64
- func (*PseudoRandom) Float32() float32
- func (*PseudoRandom) Float64() float64
- func (*PseudoRandom) Int() int
- func (*PseudoRandom) Int32() int32
- func (*PseudoRandom) Int32N(n int32) int32
- func (*PseudoRandom) Int64() int64
- func (*PseudoRandom) Int64N(n int64) int64
- func (*PseudoRandom) IntN(n int) int
- func (*PseudoRandom) N[Int intType](n Int) Int
- func (*PseudoRandom) NormFloat64() float64
- func (*PseudoRandom) Perm(n int) []int
- func (*PseudoRandom) Shuffle(n int, swap func(i, j int))
- func (*PseudoRandom) Uint() uint
- func (*PseudoRandom) Uint32() uint32
- func (*PseudoRandom) Uint32N(n uint32) uint32
- func (*PseudoRandom) Uint64() uint64
- func (*PseudoRandom) Uint64N(n uint64) uint64
- func (*PseudoRandom) UintN(n uint) uint
- type Rand
- func (r *Rand) Digits(length int, hasLeadingZero ...bool) string
- func (r *Rand) Duration(min, max time.Duration) time.Duration
- func (r *Rand) ExpFloat64() float64
- func (r *Rand) Float32() float32
- func (rd *Rand) Float32R(min, max float32) float32
- func (r *Rand) Float64() float64
- func (rd *Rand) Float64R(min, max float64) float64
- func (r *Rand) Int() int
- func (r *Rand) Int32() int32
- func (r *Rand) Int32N(n int32) int32
- func (rd *Rand) Int32R(min, max int32) int32
- func (r *Rand) Int64() int64
- func (r *Rand) Int64N(n int64) int64
- func (rd *Rand) Int64R(min, max int64) int64
- func (r *Rand) IntN(n int) int
- func (rd *Rand) IntR(min, max int) int
- func (r *Rand) Letters(length int) string
- func (r *Rand) Lucky(probability float64, base ...float64) bool
- func (r *Rand) NormFloat64() float64
- func (r *Rand) Perm(n int) []int
- func (r *Rand) Shuffle[T any](list []T)
- func (r *Rand) Str(seed string, length int) string
- func (r *Rand) Symbols(length int) string
- func (r *Rand) Uint() uint
- func (r *Rand) Uint32() uint32
- func (r *Rand) Uint32N(n uint32) uint32
- func (r *Rand) Uint64() uint64
- func (r *Rand) Uint64N(n uint64) uint64
- func (r *Rand) UintN(n uint) uint
- func (rd *Rand) Weight[T any](fn func(v T) float64, list ...T) (int, T, bool)
- type Random
- type TrueRandom
- func (r *TrueRandom) ExpFloat64() float64
- func (r *TrueRandom) Float32() float32
- func (r *TrueRandom) Float64() float64
- func (r *TrueRandom) Int() int
- func (r *TrueRandom) Int32() int32
- func (r *TrueRandom) Int32N(n int32) int32
- func (r *TrueRandom) Int64() int64
- func (r *TrueRandom) Int64N(n int64) int64
- func (r *TrueRandom) IntN(n int) int
- func (r *TrueRandom) N[Int intType](n Int) Int
- func (r *TrueRandom) NormFloat64() float64
- func (r *TrueRandom) Perm(n int) []int
- func (r *TrueRandom) Shuffle(n int, swap func(i, j int))
- func (r *TrueRandom) Uint() uint
- func (r *TrueRandom) Uint32() uint32
- func (r *TrueRandom) Uint32N(n uint32) uint32
- func (r *TrueRandom) Uint64() uint64
- func (r *TrueRandom) Uint64N(n uint64) uint64
- func (r *TrueRandom) UintN(n uint) uint
Constants ¶
const ( LetterSeed = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" // Upper- and lower-case letters LetterLowerSeed = "abcdefghijklmnopqrstuvwxyz" // Lower-case letters LetterUpperSeed = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" // Upper-case letters DigitSeed = "0123456789" // Digits DigitWithoutZeroSeed = "123456789" // Digits without zero SymbolSeed = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" // Special characters )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PseudoRandom ¶
type PseudoRandom struct{}
PseudoRandom is a pseudo-random number generator implemented on top of math/rand/v2.
It keeps no internal state and the global functions of math/rand/v2 are safe for concurrent use, so a PseudoRandom is safe to share across goroutines.
func (*PseudoRandom) ExpFloat64 ¶
func (*PseudoRandom) ExpFloat64() float64
ExpFloat64 returns a pseudo-random 64-bit float from an exponential distribution with rate parameter (lambda) 1 and mean 1.
func (*PseudoRandom) Float32 ¶
func (*PseudoRandom) Float32() float32
Float32 returns a pseudo-random 32-bit float in [0.0,1.0).
func (*PseudoRandom) Float64 ¶
func (*PseudoRandom) Float64() float64
Float64 returns a pseudo-random 64-bit float in [0.0,1.0).
func (*PseudoRandom) Int ¶
func (*PseudoRandom) Int() int
Int returns a non-negative pseudo-random integer.
func (*PseudoRandom) Int32 ¶
func (*PseudoRandom) Int32() int32
Int32 returns a non-negative pseudo-random 31-bit integer.
func (*PseudoRandom) Int32N ¶
func (*PseudoRandom) Int32N(n int32) int32
Int32N returns a non-negative pseudo-random 32-bit integer in [0,n). n must be greater than 0.
func (*PseudoRandom) Int64 ¶
func (*PseudoRandom) Int64() int64
Int64 returns a non-negative pseudo-random 63-bit integer.
func (*PseudoRandom) Int64N ¶
func (*PseudoRandom) Int64N(n int64) int64
Int64N returns a non-negative pseudo-random 64-bit integer in [0,n). n must be greater than 0.
func (*PseudoRandom) IntN ¶
func (*PseudoRandom) IntN(n int) int
IntN returns a non-negative pseudo-random integer in [0,n). n must be greater than 0.
func (*PseudoRandom) N ¶
func (*PseudoRandom) N[Int intType](n Int) Int
N returns a pseudo-random integer in [0,n) for any integer type. n must be greater than 0.
func (*PseudoRandom) NormFloat64 ¶
func (*PseudoRandom) NormFloat64() float64
NormFloat64 returns a pseudo-random 64-bit float from the standard normal distribution (mean 0, standard deviation 1).
func (*PseudoRandom) Perm ¶
func (*PseudoRandom) Perm(n int) []int
Perm returns a pseudo-random permutation of the integers in [0,n).
func (*PseudoRandom) Shuffle ¶
func (*PseudoRandom) Shuffle(n int, swap func(i, j int))
Shuffle randomizes the order of the elements using swap. n is the number of elements and must not be negative.
func (*PseudoRandom) Uint ¶
func (*PseudoRandom) Uint() uint
Uint returns a pseudo-random unsigned integer.
func (*PseudoRandom) Uint32 ¶
func (*PseudoRandom) Uint32() uint32
Uint32 returns a pseudo-random 32-bit unsigned integer.
func (*PseudoRandom) Uint32N ¶
func (*PseudoRandom) Uint32N(n uint32) uint32
Uint32N returns a non-negative pseudo-random 32-bit unsigned integer in [0,n). n must be greater than 0.
func (*PseudoRandom) Uint64 ¶
func (*PseudoRandom) Uint64() uint64
Uint64 returns a pseudo-random 64-bit unsigned integer.
func (*PseudoRandom) Uint64N ¶
func (*PseudoRandom) Uint64N(n uint64) uint64
Uint64N returns a non-negative pseudo-random 64-bit unsigned integer in [0,n). n must be greater than 0.
func (*PseudoRandom) UintN ¶
func (*PseudoRandom) UintN(n uint) uint
UintN returns a non-negative pseudo-random unsigned integer in [0,n). n must be greater than 0.
type Rand ¶
type Rand struct {
// contains filtered or unexported fields
}
func NewRand ¶
NewRand returns a new random number generator backed by rng.
Passing true for safe enables concurrency safety by guarding rng with a mutex.
func (*Rand) Digits ¶
Digits returns a random digit string of the given length. By default the first digit is not zero unless hasLeadingZero is true.
func (*Rand) ExpFloat64 ¶
ExpFloat64 returns a 64-bit float from an exponential distribution with rate parameter (lambda) 1 and mean 1.
func (*Rand) Int32N ¶
Int32N returns a non-negative pseudo-random 32-bit integer in [0,n). n must be greater than 0.
func (*Rand) Int64N ¶
Int64N returns a non-negative pseudo-random 64-bit integer in [0,n). n must be greater than 0.
func (*Rand) IntN ¶
IntN returns a non-negative pseudo-random integer in [0,n). n must be greater than 0.
func (*Rand) NormFloat64 ¶
NormFloat64 returns a 64-bit float from the standard normal distribution (mean 0, standard deviation 1).
func (*Rand) Symbols ¶
Symbols returns a random string of the given length built from special characters.
func (*Rand) Uint32N ¶
Uint32N returns a non-negative pseudo-random 32-bit unsigned integer in [0,n). n must be greater than 0.
func (*Rand) Uint64N ¶
Uint64N returns a non-negative pseudo-random 64-bit unsigned integer in [0,n). n must be greater than 0.
func (*Rand) UintN ¶
UintN returns a non-negative pseudo-random unsigned integer in [0,n). n must be greater than 0.
type Random ¶
type Random interface {
Int() int
IntN(n int) int
Int32() int32
Int32N(n int32) int32
Int64() int64
Int64N(n int64) int64
Uint() uint
UintN(n uint) uint
Uint32() uint32
Uint32N(n uint32) uint32
Uint64() uint64
Uint64N(n uint64) uint64
Float32() float32
Float64() float64
ExpFloat64() float64
NormFloat64() float64
Perm(n int) []int
Shuffle(n int, swap func(i, j int))
}
type TrueRandom ¶
type TrueRandom struct{}
TrueRandom is a true random number generator implemented on top of crypto/rand.
It keeps no internal state and the underlying crypto/rand.Read is safe for concurrent use, so a TrueRandom is safe to share across goroutines.
func (*TrueRandom) ExpFloat64 ¶
func (r *TrueRandom) ExpFloat64() float64
ExpFloat64 returns a true random 64-bit float from an exponential distribution with rate parameter (lambda) 1 and mean 1, generated by inverse transform sampling.
func (*TrueRandom) Float32 ¶
func (r *TrueRandom) Float32() float32
Float32 returns a true random 32-bit float in [0.0,1.0).
func (*TrueRandom) Float64 ¶
func (r *TrueRandom) Float64() float64
Float64 returns a true random 64-bit float in [0.0,1.0).
func (*TrueRandom) Int ¶
func (r *TrueRandom) Int() int
Int returns a non-negative true random integer.
func (*TrueRandom) Int32 ¶
func (r *TrueRandom) Int32() int32
Int32 returns a non-negative true random 31-bit integer.
func (*TrueRandom) Int32N ¶
func (r *TrueRandom) Int32N(n int32) int32
Int32N returns a non-negative true random 32-bit integer in [0,n). n must be greater than 0.
func (*TrueRandom) Int64 ¶
func (r *TrueRandom) Int64() int64
Int64 returns a non-negative true random 63-bit integer.
func (*TrueRandom) Int64N ¶
func (r *TrueRandom) Int64N(n int64) int64
Int64N returns a non-negative true random 64-bit integer in [0,n). n must be greater than 0.
func (*TrueRandom) IntN ¶
func (r *TrueRandom) IntN(n int) int
IntN returns a non-negative true random integer in [0,n). n must be greater than 0.
func (*TrueRandom) N ¶
func (r *TrueRandom) N[Int intType](n Int) Int
N returns a true random integer in [0,n) for any integer type. n must be greater than 0.
func (*TrueRandom) NormFloat64 ¶
func (r *TrueRandom) NormFloat64() float64
NormFloat64 returns a true random 64-bit float from the standard normal distribution (mean 0, standard deviation 1), generated by transforming a uniform distribution with the Box-Muller method.
func (*TrueRandom) Perm ¶
func (r *TrueRandom) Perm(n int) []int
Perm returns a true random permutation of the integers in [0,n).
func (*TrueRandom) Shuffle ¶
func (r *TrueRandom) Shuffle(n int, swap func(i, j int))
Shuffle randomizes the order of the elements using swap. n is the number of elements and must not be negative.
func (*TrueRandom) Uint ¶
func (r *TrueRandom) Uint() uint
Uint returns a true random unsigned integer.
func (*TrueRandom) Uint32 ¶
func (r *TrueRandom) Uint32() uint32
Uint32 returns a true random 32-bit unsigned integer.
func (*TrueRandom) Uint32N ¶
func (r *TrueRandom) Uint32N(n uint32) uint32
Uint32N returns a non-negative true random 32-bit unsigned integer in [0,n). n must be greater than 0.
func (*TrueRandom) Uint64 ¶
func (r *TrueRandom) Uint64() uint64
Uint64 returns a true random 64-bit unsigned integer.
func (*TrueRandom) Uint64N ¶
func (r *TrueRandom) Uint64N(n uint64) uint64
Uint64N returns a non-negative true random 64-bit unsigned integer in [0,n). n must be greater than 0.
func (*TrueRandom) UintN ¶
func (r *TrueRandom) UintN(n uint) uint
UintN returns a non-negative true random unsigned integer in [0,n). n must be greater than 0.