Documentation
¶
Index ¶
- func AlphaNumeric(n int) string
- func Bool() bool
- func Byte() byte
- func BytesN(n int, low, high byte) []byte
- func BytesSeqN(n int, low, high byte) string
- func DigitsN(n int) string
- func ExpFloat64() float64
- func Float32() float32
- func Float32Range(min, max float32) float32
- func Float64() float64
- func Float64Range(min, max float64) float64
- func Int() int
- func Int32() int32
- func Int32N(max int32) int32
- func Int32Range(min, max int32) int32
- func Int64() int64
- func Int64N(max int64) int64
- func Int64Range(min, max int64) int64
- func IntN(max int) int
- func IntRange(min, max int) int
- func Letters(n int) string
- func LowerN(n int) string
- func NormFloat64() float64
- func Perm(n int) []int
- func Rune() rune
- func RunesN(n int, low, high rune) []rune
- func RunesSeq(n int, low, high rune) string
- func SecAlphaNumeric(n int) string
- func SecBool() bool
- func SecByte() byte
- func SecBytesN(n int, low, high byte) []byte
- func SecBytesSeqN(n int, low, high byte) string
- func SecDigitsN(n int) string
- func SecExpFloat64() float64
- func SecFloat32() float32
- func SecFloat32Range(min, max float32) float32
- func SecFloat64() float64
- func SecFloat64Range(min, max float64) float64
- func SecInt() int
- func SecInt32() int32
- func SecInt32N(n int32) int32
- func SecInt32Range(min, max int32) int32
- func SecInt64() int64
- func SecInt64N(n int64) int64
- func SecInt64Range(min, max int64) int64
- func SecIntN(n int) int
- func SecIntRange(min, max int) int
- func SecLetters(n int) string
- func SecLowerN(n int) string
- func SecNormFloat64() float64
- func SecPerm(n int) []int
- func SecRune() rune
- func SecRunesN(n int, low, high rune) []rune
- func SecRunesSeq(n int, low, high rune) string
- func SecShuffle(n int, swap func(i, j int))
- func SecTime(since, until time.Time) time.Time
- func SecUint() uint
- func SecUint32() uint32
- func SecUint32N(n uint32) uint32
- func SecUint32Range(min, max uint32) uint32
- func SecUint64() uint64
- func SecUint64N(max uint64) uint64
- func SecUint64Range(min, max uint64) uint64
- func SecUintN(n uint) uint
- func SecUintRange(min, max uint) uint
- func SecUpperN(n int) string
- func Shuffle(n int, swap func(i, j int))
- func Time(since, until time.Time) time.Time
- func Uint() uint
- func Uint32() uint32
- func Uint32N(max uint32) uint32
- func Uint32Range(min, max uint32) uint32
- func Uint64() uint64
- func Uint64N(max uint64) uint64
- func Uint64Range(min, max uint64) uint64
- func UintN(max uint) uint
- func UintRange(min, max uint) uint
- func Upper(n int) string
- type Rand
- func (r *Rand) AlphaNumericN(n int) string
- func (r *Rand) Bool() bool
- func (r *Rand) Byte() byte
- func (r *Rand) BytesN(n int, low, high byte) []byte
- func (r *Rand) DigitsN(n int) string
- func (r *Rand) Float32Range(min, max float32) float32
- func (r *Rand) Float64Range(min, max float64) float64
- func (r *Rand) Int32Range(min, max int32) int32
- func (r *Rand) Int64Range(min, max int64) int64
- func (r *Rand) IntRange(min, max int) int
- func (r *Rand) LettersN(n int) string
- func (r *Rand) LowerN(n int) string
- func (r *Rand) Rune() rune
- func (r *Rand) RunesN(n int, low, high rune) []rune
- func (r *Rand) Time(since, until time.Time) time.Time
- func (r *Rand) Uint32Range(min, max uint32) uint32
- func (r *Rand) Uint64Range(min, max uint64) uint64
- func (r *Rand) UintRange(min, max uint) uint
- func (r *Rand) UpperN(n int) string
- type Source
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AlphaNumeric ¶
AlphaNumeric generates a random string of n alphanumeric characters using the default random source.
func BytesN ¶
BytesN generates a random slice of n bytes in the range [low, high] using the default random source.
func ExpFloat64 ¶
func ExpFloat64() float64
ExpFloat64 returns a random float64 with an exponential distribution.
func Float32Range ¶
Float32Range returns a random float32 in the range [min, max).
func Float64Range ¶
Float64Range returns a random float64 in the range [min, max).
func Int32Range ¶
Int32Range returns a random 32-bit integer in the range [min, max).
func Int64Range ¶
Int64Range returns a random 64-bit integer in the range [min, max).
func Letters ¶
Letters generates a random string of n letters (mixed case) using the default random source.
func LowerN ¶
LowerN generates a random string of n lowercase letters using the default random source.
func NormFloat64 ¶
func NormFloat64() float64
NormFloat64 returns a random float64 with a normal distribution.
func RunesN ¶
RunesN generates a random slice of n runes in the range [low, high] using the default random source.
func SecAlphaNumeric ¶
SecAlphaNumeric generates a cryptographically secure random string of n alphanumeric characters.
func SecBytesN ¶
SecBytesN generates a cryptographically secure random slice of n bytes in the range [low, high].
func SecBytesSeqN ¶
SecBytesSeqN generates a cryptographically secure random slice of n bytes as a string.
func SecDigitsN ¶
SecDigitsN generates a cryptographically secure random string of n digits.
func SecExpFloat64 ¶
func SecExpFloat64() float64
SecExpFloat64 returns a secure random float64 with an exponential distribution.
func SecFloat32 ¶
func SecFloat32() float32
SecFloat32 returns a secure random float32 in the range [0.0, 1.0).
func SecFloat32Range ¶
SecFloat32Range returns a secure random float32 in the range [min, max).
func SecFloat64 ¶
func SecFloat64() float64
SecFloat64 returns a secure random float64 in the range [0.0, 1.0).
func SecFloat64Range ¶
SecFloat64Range returns a secure random float64 in the range [min, max).
func SecInt32Range ¶
SecInt32Range returns a secure random 32-bit integer in the range [min, max).
func SecInt64Range ¶
SecInt64Range returns a secure random 64-bit integer in the range [min, max).
func SecIntRange ¶
SecIntRange returns a secure random integer in the range [min, max).
func SecLetters ¶
SecLetters generates a cryptographically secure random string of n letters (mixed case).
func SecLowerN ¶
SecLowerN generates a cryptographically secure random string of n lowercase letters.
func SecNormFloat64 ¶
func SecNormFloat64() float64
SecNormFloat64 returns a secure random float64 with a normal distribution.
func SecPerm ¶
SecPerm returns a slice of n distinct random non-negative integers in [0, n) using a cryptographically secure random number generator.
func SecRunesN ¶
SecRunesN generates a cryptographically secure random slice of n runes in the range [low, high].
func SecRunesSeq ¶
SecRunesSeq generates a cryptographically secure random slice of n runes as a string.
func SecShuffle ¶
SecShuffle shuffles the first n elements of data using a cryptographically secure random number generator.
func SecTime ¶
SecTime returns a random time within the given range [since, until) using the secure source.
func SecUint32N ¶
SecUint32N returns a secure random 32-bit unsigned integer in the range [0, n).
func SecUint32Range ¶
SecUint32Range returns a secure random 32-bit unsigned integer in the range [min, max).
func SecUint64N ¶
SecUint64N returns a secure random 64-bit unsigned integer in the range [0, n).
func SecUint64Range ¶
SecUint64Range returns a secure random 64-bit unsigned integer in the range [min, max).
func SecUintRange ¶
SecUintRange returns a secure random unsigned integer in the range [min, max).
func SecUpperN ¶
SecUpperN generates a cryptographically secure random string of n uppercase letters.
func Time ¶
Time returns a random time within the given range [since, until) using the default source.
func Uint32Range ¶
Uint32Range returns a random 32-bit unsigned integer in the range [min, max).
func Uint64Range ¶
Uint64Range returns a random 64-bit unsigned integer in the range [min, max).
Types ¶
type Rand ¶
Rand is an enhance number generator for *math/rand/v2.Rand. #nosec G404 (CWE-338): Use of weak random number generator
func New ¶
New returns a new Rand using the provided source. #nosec G404 (CWE-338): Use of weak random number generator
func NewChaCha8 ¶
func NewChaCha8() *Rand
NewChaCha8 returns a new non-concurrent-safe ChaCha8 random number generator. ChaCha8Rng is a variant of the ChaCha stream cipher, designed for high-speed encryption and random number generation. It offers: - Strong cryptographic properties - Excellent performance on a wide range of platforms - Resistance to timing attacks - Simple and efficient implementation This implementation uses PCG to generate the initial seed. #nosec G404 (CWE-338): Use of weak random number generator
func NewCrypto ¶
func NewCrypto() *Rand
NewCrypto returns a new concurrent-safe cryptographically secure random number generator. It utilizes the operating system's cryptographically secure random number generator: - Windows: Uses CryptGenRandom, which leverages the CryptoAPI - Linux: Uses getrandom() system call, falling back to /dev/urandom if unavailable - macOS: Uses SecRandomCopyBytes, which is backed by the Yarrow algorithm This generator offers: - High-quality, unpredictable random numbers suitable for cryptographic use - Protection against common cryptographic attacks - Automatic seeding from system entropy sources - Consistent interface across different operating systems Note: While highly secure, this generator may be slower than non-cryptographic alternatives.
func NewCryptoBackoff ¶
NewCryptoBackoff returns a new concurrent-safe cryptographically secure random number generator with a specified backoff generator.
func NewPCG ¶
func NewPCG() *Rand
NewPCG returns a new non-concurrent-safe PCG random number generator. PCG (Permuted Congruential Generator) is a family of simple, fast, and statistically excellent random number generators. It offers: - High statistical quality output - Small state size and fast period advancement - Excellent performance on various platforms - Multiple, independent streams - Simple and efficient implementation This implementation uses runtime and system information to generate the initial seeds. #nosec G404 (CWE-338): Use of weak random number generator
func NewRuntime ¶
func NewRuntime() *Rand
NewRuntime returns a new concurrent-safe, high-speed random number generator. This generator offers: - Concurrent safety through goroutine-local random number generators - High performance suitable for non-cryptographic use cases - Based on the ChaCha8 algorithm for quality randomness - Automatic seeding from runtime information Concurrency safety is achieved by utilizing Go's runtime, where each goroutine has its own local random number generator. This approach eliminates the need for locks or atomic operations, resulting in excellent performance in concurrent scenarios. The underlying algorithm is ChaCha8, which provides a good balance of speed and randomness quality. Note: While fast and suitable for many applications, this is not cryptographically secure.
func NewZipf ¶
func NewZipf() *Rand
NewZipf returns a new non-concurrent-safe Zipf-distributed random number generator. Zipf distribution is a discrete probability distribution commonly used for modeling: - Word frequencies in natural languages - Population sizes of cities - Income distribution in economics It offers: - Power-law behavior for modeling real-world phenomena - Adjustable parameters for different distribution shapes - Efficient generation of skewed random numbers - Suitable for various applications in data science and simulations This implementation uses PCG as the underlying random source with dynamic parameters. #nosec G404 (CWE-338): Use of weak random number generator
func (*Rand) AlphaNumericN ¶
AlphaNumericN generates a random string of n alphanumeric characters.
func (*Rand) Float32Range ¶
Float32Range returns a random float32 in the range [min, max).
func (*Rand) Float64Range ¶
Float64Range returns a random float64 in the range [min, max).
func (*Rand) Int32Range ¶
Int32Range returns a random int32 in the range [min, max).
func (*Rand) Int64Range ¶
Int64Range returns a random int64 in the range [min, max).
func (*Rand) Uint32Range ¶
Uint32Range returns a random uint32 in the range [min, max).
func (*Rand) Uint64Range ¶
Uint64Range returns a random uint64 in the range [min, max).