rand

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2025 License: MIT Imports: 4 Imported by: 0

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

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

func NewRNG(seed int64) (*RNG, int64, error)

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

func (r *RNG) ExpFloat64() float64

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

func (r *RNG) Float32() float32

Float32 returns, as a float32, a pseudo-random number in the half-open interval [0.0,1.0).

func (*RNG) Float64

func (r *RNG) Float64() float64

Float64 returns, as a float64, a pseudo-random number in the half-open interval [0.0,1.0).

func (*RNG) GetSeed

func (r *RNG) GetSeed() int64

GetSeed returns the current seed value.

Returns:

  • The current seed value

func (*RNG) Int

func (r *RNG) Int() int

Int returns a non-negative pseudo-random int.

func (*RNG) Int63

func (r *RNG) Int63() int64

Int63 returns a non-negative pseudo-random 63-bit integer as an int64.

func (*RNG) Int64

func (r *RNG) Int64() int64

Int64 returns a pseudo-random 64-bit value as an int64.

func (*RNG) Int64N

func (r *RNG) Int64N(n int64) int64

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

func (r *RNG) IntN(n int) int

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

func (r *RNG) NormFloat64() float64

NormFloat64 returns a normally distributed float64 in the range [-math.MaxFloat64, +math.MaxFloat64] with standard normal distribution (mean = 0, stddev = 1).

func (*RNG) Perm

func (r *RNG) Perm(n int) []int

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

func (r *RNG) Seed(seed int64) (int64, error)

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

func (*RNG) Shuffle

func (r *RNG) Shuffle(n int, swap func(i, j int))

Shuffle pseudo-randomizes the order of elements using the Fisher-Yates shuffle algorithm. It panics if n < 0.

func (*RNG) Uint64

func (r *RNG) Uint64() uint64

Uint64 returns a pseudo-random 64-bit value as a uint64.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL