Documentation
¶
Index ¶
- Constants
- Variables
- func Float64RangeSecure(_min, _max float64) float64
- func Float64Secure() float64
- func IntBetweenSecure(_min, _max int) int
- func IntNSecure(n int) int
- func IntRangeSecure(_min, _max int) int
- func RandBetween(minV, maxV int) int
- func RandBetweenSecure(minV, maxV int) int
- func RandInt() int
- func RandInt32() int32
- func RandInt32Secure() int32
- func RandInt64() int64
- func RandInt64Secure() int64
- func RandIntSecure() int
- func RandUint() uint
- func RandUint32() uint32
- func RandUint32Secure() uint32
- func RandUint64() uint64
- func RandUint64Secure() uint64
- func RandUintSecure() uint
- func Shuffle(ss Swapper)
- func SimpleRandBetween(minV, maxV int) int
- type PassGen
- type RandGen
- type RandomChan
- func (x *RandomChan) Close()
- func (x *RandomChan) Float64() float64
- func (x *RandomChan) Float64Range(_min, _max float64) float64
- func (x *RandomChan) IntBetween(_min, _max int) int
- func (x *RandomChan) IntN(n int) int
- func (x *RandomChan) IntRange(_min, _max int) int
- func (x *RandomChan) ReadBytes(n int) []byte
- func (x *RandomChan) Uint64() uint64
- type Swapper
Constants ¶
const ( // ChanBufferSize defines channel buffer capacity: 1M * 8 bytes = 8MB total buffer ChanBufferSize = 1024 * 1024 // ChanChunkSize defines how many bytes to read from crypto/rand each time: 1024 bytes ChanChunkSize = 1024 )
Variables ¶
var ( // ZeroUnit represents an all-zero 8-byte unit returned when generator is closed ZeroUnit = [8]byte{} )
Functions ¶
func Float64RangeSecure ¶ added in v1.3.11
Float64RangeSecure returns a random float64 in [min, max) range Uses linear transformation to maintain uniform distribution
func Float64Secure ¶ added in v1.3.11
func Float64Secure() float64
Float64Secure returns a float64 in [0, 1) range Uses 53 bits for proper float64 precision
func IntBetweenSecure ¶ added in v1.3.11
IntBetweenSecure returns a random int in [min, max] range (inclusive) Convenient wrapper for common range operations
func IntNSecure ¶ added in v1.3.11
IntNSecure random generate int, read data from linux /dev/urandom in range [0, n)
func IntRangeSecure ¶ added in v1.3.11
IntRangeSecure returns a random int in [min, max) range Convenient wrapper for common range operations
func RandBetween ¶
RandBetween : generate rand between [a, b], return int
func RandBetweenSecure ¶
RandBetweenSecure : generate rand between [a, b], return int
func RandInt32 ¶
func RandInt32() int32
RandInt32 random generate int32, rand seed is current nano timestamp
func RandInt32Secure ¶
func RandInt32Secure() int32
RandInt32Secure random generate int32, read data from linux /dev/urandom actually, it's almost a random id
func RandInt64 ¶
func RandInt64() int64
RandInt64 random generate int64, rand seed is current nano timestamp
func RandInt64Secure ¶
func RandInt64Secure() int64
RandInt64Secure random generate int64, read data from linux /dev/urandom actually, it's almost a random id
func RandIntSecure ¶
func RandIntSecure() int
RandIntSecure random generate int, read data from linux /dev/urandom actually, it's almost a random id
func RandUint ¶
func RandUint() uint
RandUint random generate uint, rand seed is current nano timestamp
func RandUint32 ¶
func RandUint32() uint32
RandUint32 random generate uint32, rand seed is current nano timestamp
func RandUint32Secure ¶
func RandUint32Secure() uint32
RandUint32Secure random generate uint32, read data from linux /dev/urandom actually, it's almost a random id
func RandUint64 ¶
func RandUint64() uint64
RandUint64 random generate uint64, rand seed is current nano timestamp
func RandUint64Secure ¶
func RandUint64Secure() uint64
RandUint64Secure random generate uint64, read data from linux /dev/urandom actually, it's almost a random id
func RandUintSecure ¶
func RandUintSecure() uint
RandUintSecure random generate uint, read data from linux /dev/urandom actually, it's almost a random id
func SimpleRandBetween ¶
SimpleRandBetween : generate rand between [a, b], use same global rand source: rand.Rand
Types ¶
type PassGen ¶ added in v1.3.12
type PassGen struct {
// contains filtered or unexported fields
}
PassGen is a password generator
func NewPassGen ¶ added in v1.3.12
NewPassGen creates a new PassGen instance
func (*PassGen) GenerateRandomPassword ¶ added in v1.3.12
GenerateRandomPassword generates a random password of specified length Requirements: - length must be at least 4 - must contain at least 1 lowercase letter - must contain at least 1 uppercase letter - must contain at least 1 digit - must contain at least 1 special character
type RandGen ¶ added in v1.3.12
type RandGen struct {
// contains filtered or unexported fields
}
RandGen is a random string generator
func NewRandGen ¶ added in v1.3.12
NewRandGen creates a new RandGen instance
type RandomChan ¶ added in v1.2.9
type RandomChan struct {
// contains filtered or unexported fields
}
RandomChan provides high-performance access to crypto/rand through channel buffering Uses 8-byte units for optimal performance with common operations like Uint64() and Float64()
func NewRandomChan ¶ added in v1.2.9
func NewRandomChan() *RandomChan
NewRandomChan creates a new channel-based crypto random generator The generator uses a background goroutine to continuously fill the channel with random data
func (*RandomChan) Close ¶ added in v1.2.9
func (x *RandomChan) Close()
Close stops the random generator gracefully Can be called multiple times safely due to sync.Once
func (*RandomChan) Float64 ¶ added in v1.2.9
func (x *RandomChan) Float64() float64
Float64 returns a float64 in [0, 1) range Uses 53 bits for proper float64 precision
func (*RandomChan) Float64Range ¶ added in v1.2.9
func (x *RandomChan) Float64Range(_min, _max float64) float64
Float64Range returns a random float64 in [min, max) range Uses linear transformation to maintain uniform distribution
func (*RandomChan) IntBetween ¶ added in v1.2.9
func (x *RandomChan) IntBetween(_min, _max int) int
IntBetween returns a random int in [min, max] range (inclusive) Convenient wrapper for common range operations
func (*RandomChan) IntN ¶ added in v1.2.9
func (x *RandomChan) IntN(n int) int
IntN returns a random int in [0, n) range Uses rejection sampling to ensure uniform distribution
func (*RandomChan) IntRange ¶ added in v1.2.9
func (x *RandomChan) IntRange(_min, _max int) int
IntRange returns a random int in [min, max) range Convenient wrapper for common range operations
func (*RandomChan) ReadBytes ¶ added in v1.2.9
func (x *RandomChan) ReadBytes(n int) []byte
ReadBytes reads n bytes from the generator Note: May waste some bytes for non-8-aligned sizes, but this is acceptable since most use cases need 8-byte multiples (Uint64, Float64, etc.)
func (*RandomChan) Uint64 ¶ added in v1.2.9
func (x *RandomChan) Uint64() uint64
Uint64 reads a uint64 random number Most efficient method as it uses exactly one 8-byte unit