Documentation
¶
Index ¶
- Constants
- Variables
- func CryptoInt(reader io.Reader, max *big.Int) (*big.Int, error)
- func ExpFloat64() float64
- func Float32() float32
- func Float64() float64
- func Int() int
- func Int31() int32
- func Int31n(n int32) int32
- func Int63() int64
- func Int63n(n int64) int64
- func Intn(n int) int
- func NormFloat64() float64
- func Perm(n int) []int
- func Prime(random io.Reader, bits int) (*big.Int, error)
- func Read(p []byte) (n int, err error)
- func ReadBigInt(max *big.Int) (*big.Int, error)
- func ReadBigIntInRange(min, max *big.Int) (*big.Int, error)
- func Seed(seed int64)
- func Shuffle(n int, swap func(i, j int))
- func Uint32() uint32
- func Uint64() uint64
- type Rand
- func (r *Rand) ExpFloat64() float64
- func (r *Rand) Float32() float32
- func (r *Rand) Float64() float64
- func (r *Rand) Int() int
- func (r *Rand) Int31() int32
- func (r *Rand) Int31n(n int32) int32
- func (r *Rand) Int63() int64
- func (r *Rand) Int63n(n int64) int64
- func (r *Rand) Intn(n int) int
- func (r *Rand) NormFloat64() float64
- func (r *Rand) Perm(n int) []int
- func (r *Rand) Seed(seed int64)
- func (r *Rand) Shuffle(n int, swap func(i, j int))
- func (r *Rand) Uint32() uint32
- func (r *Rand) Uint64() uint64
- type SecureReader
- type Source
- type Source64
Constants ¶
const ( // Minimum entropy threshold for random data (bits per byte) // Reduced to 4.0 for crypto/rand compatibility while still catching patterns MinEntropyThreshold = 4.0 // Maximum retry attempts for entropy validation MaxEntropyRetries = 10 // Sample size for entropy testing EntropySampleSize = 1024 )
Entropy validation constants
Variables ¶
var ( ErrInsufficientEntropy = oops.Errorf("insufficient entropy in random source") ErrRandomReadFailed = oops.Errorf("failed to read from random source") ErrEntropyValidation = oops.Errorf("entropy validation failed") )
Common errors for random number generation
var DefaultSecureReader = NewSecureReader()
Global secure reader instance
var Reader io.Reader = DefaultSecureReader
Reader is the global, shared instance of a cryptographically secure random number generator Compatible with crypto/rand.Reader
Functions ¶
func CryptoInt ¶
CryptoInt returns a uniform random value in [0, max). It panics if max <= 0. Compatible with crypto/rand.Int function
func ExpFloat64 ¶
func ExpFloat64() float64
ExpFloat64 returns an exponentially distributed float64 with rate parameter 1
func Float32 ¶
func Float32() float32
Float32 returns, as a float32, a pseudo-random number in [0.0,1.0)
func Float64 ¶
func Float64() float64
Float64 returns, as a float64, a pseudo-random number in [0.0,1.0)
func Int31 ¶
func Int31() int32
Int31 returns a non-negative pseudo-random 31-bit integer as an int32
func Int63 ¶
func Int63() int64
Int63 returns a non-negative pseudo-random 63-bit integer as an int64
func NormFloat64 ¶
func NormFloat64() float64
NormFloat64 returns a normally distributed float64 in the range [-math.MaxFloat64, +math.MaxFloat64]
func Prime ¶
Prime returns a number of the given bit length that is prime with high probability. Compatible with crypto/rand.Prime function
func ReadBigInt ¶
ReadBigInt generates a cryptographically secure big.Int in the range [0, max)
func ReadBigIntInRange ¶
ReadBigIntInRange generates a cryptographically secure big.Int in the range [min, max)
func Seed ¶
func Seed(seed int64)
Seed uses the provided seed value to initialize the default Source
Types ¶
type Rand ¶
type Rand struct {
// contains filtered or unexported fields
}
Rand represents a source of random numbers with math/rand compatibility
func (*Rand) ExpFloat64 ¶
ExpFloat64 returns an exponentially distributed float64 with rate parameter 1 Compatible with math/rand.ExpFloat64
func (*Rand) Float32 ¶
Float32 returns, as a float32, a pseudo-random number in [0.0,1.0) Compatible with math/rand.Float32
func (*Rand) Float64 ¶
Float64 returns, as a float64, a pseudo-random number in [0.0,1.0) Compatible with math/rand.Float64
func (*Rand) Int31 ¶
Int31 returns a non-negative pseudo-random 31-bit integer as an int32 Compatible with math/rand.Int31
func (*Rand) Int31n ¶
Int31n returns, as an int32, a non-negative pseudo-random number in [0,n) Compatible with math/rand.Int31n
func (*Rand) Int63 ¶
Int63 returns a non-negative pseudo-random 63-bit integer as an int64 Compatible with math/rand.Int63
func (*Rand) Int63n ¶
Int63n returns, as an int64, a non-negative pseudo-random number in [0,n) Compatible with math/rand.Int63n
func (*Rand) Intn ¶
Intn returns, as an int, a non-negative pseudo-random number in [0,n) Compatible with math/rand.Intn
func (*Rand) NormFloat64 ¶
NormFloat64 returns a normally distributed float64 in the range [-math.MaxFloat64, +math.MaxFloat64] Compatible with math/rand.NormFloat64
func (*Rand) Perm ¶
Perm returns, as a slice of n ints, a pseudo-random permutation of the integers [0,n) Compatible with math/rand.Perm
func (*Rand) Seed ¶
Seed uses the provided seed value to initialize the generator Compatible with math/rand.Seed
func (*Rand) Shuffle ¶
Shuffle pseudo-randomizes the order of elements using the Fisher-Yates shuffle Compatible with math/rand.Shuffle
type SecureReader ¶
type SecureReader struct {
// contains filtered or unexported fields
}
SecureReader provides cryptographically secure random number generation with entropy validation for the go-i2p/crypto library
func NewSecureReader ¶
func NewSecureReader() *SecureReader
NewSecureReader creates a new SecureReader using crypto/rand as the source
func (*SecureReader) Read ¶
func (sr *SecureReader) Read(p []byte) (n int, err error)
Read fills the provided byte slice with cryptographically secure random data and validates entropy before returning
func (*SecureReader) ReadBigInt ¶
ReadBigInt generates a cryptographically secure big.Int in the range [0, max)
func (*SecureReader) ReadBigIntInRange ¶
ReadBigIntInRange generates a cryptographically secure big.Int in the range [min, max)