Documentation
¶
Overview ¶
Package rand provides RNG utilities for Gymnasium-Go, based on math/rand/v2.
This package provides seeding, generator, and random number generation functions similar to Python Gymnasium's seeding utilities, ensuring reproducible behavior across reinforcement learning experiments.
Index ¶
- type RNG
- func (r *RNG) ExpFloat64() float64
- func (r *RNG) Float32() float32
- func (r *RNG) Float64() float64
- func (r *RNG) GetSeed() int64
- func (r *RNG) Int() int
- func (r *RNG) Int63() int64
- func (r *RNG) Int64() int64
- func (r *RNG) Int64N(n int64) int64
- func (r *RNG) IntN(n int) int
- func (r *RNG) NormFloat64() float64
- func (r *RNG) Perm(n int) []int
- func (r *RNG) Seed(seed int64) (int64, error)
- func (r *RNG) Shuffle(n int, swap func(i, j int))
- func (r *RNG) Uint64() uint64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RNG ¶
type RNG struct {
// contains filtered or unexported fields
}
RNG is a seeded random number generator that provides thread-safe random number generation with comprehensive utility methods for reinforcement learning environments.
func GetDefaultRNG ¶
func GetDefaultRNG() *RNG
DefaultRNG returns the singleton default RNG instance.
This is thread-safe and will be initialized with a random seed on first access.
Returns:
- The default RNG instance
func NewRNG ¶
NewRNG creates a new RNG instance with the given seed.
If seed is 0, a random seed based on current time will be used. This function validates the seed and returns an error for invalid values.
Parameters:
- seed: The seed value for the RNG. Must be non-negative.
Returns:
- A new RNG instance
- The effective seed used (useful when seed=0)
- An error if the seed is invalid
func (*RNG) ExpFloat64 ¶
ExpFloat64 returns an exponentially distributed float64 in the range (0, +math.MaxFloat64] with an exponential distribution whose rate parameter (lambda) is 1.
func (*RNG) Float32 ¶
Float32 returns, as a float32, a pseudo-random number in the half-open interval [0.0,1.0).
func (*RNG) Float64 ¶
Float64 returns, as a float64, a pseudo-random number in the half-open interval [0.0,1.0).
func (*RNG) Int64N ¶
Int64N returns, as an int64, a non-negative pseudo-random number in the half-open interval [0,n). It panics if n <= 0.
func (*RNG) IntN ¶
IntN returns, as an int, a non-negative pseudo-random number in the half-open interval [0,n). It panics if n <= 0.
func (*RNG) NormFloat64 ¶
NormFloat64 returns a normally distributed float64 in the range [-math.MaxFloat64, +math.MaxFloat64] with standard normal distribution (mean = 0, stddev = 1).
func (*RNG) Perm ¶
Perm returns, as a slice of n ints, a pseudo-random permutation of the integers [0,n). It panics if n < 0.
func (*RNG) Seed ¶
Seed resets the RNG with a new seed value.
Parameters:
- seed: The new seed value. Must be non-negative.
Returns:
- The effective seed used
- An error if the seed is invalid