random

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2025 License: AGPL-3.0 Imports: 3 Imported by: 2

Documentation

Overview

Package random contains various methods for creating random values.

Package random contains various methods for creating random values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Angle

func Angle() float64

Angle returns a random angle from 0 to 2PI radians.

func Around

func Around(val, amt float64) float64

Around returns a random float around a given number. val is the center. amt is how much on either side the result will vary.

func Bit added in v0.7.2

func Bit() int

Bit returns a random 1 or 0

func Boolean

func Boolean() bool

Boolean returns a random boolean.

func Byte added in v0.7.2

func Byte() byte

Byte returns a random byte [0, 255]

func Element

func Element[T any](list []T) T

Element returns a random element from the slice. Can't make this an instance method because generic methods cannot contain typed params and the receiver is actually a type param.

func Float

func Float() float64

Float returns a random float from 0.0 to 1.0.

func FloatArray

func FloatArray(size int, minVal, maxVal float64) []float64

FloatArray returns an array of a given size filled with random floats from minVal to maxVal.

func FloatRange

func FloatRange(minVal float64, maxVal float64) float64

FloatRange returns a random float from minVal to maxVal.

func GaussRange

func GaussRange(minVal, maxVal float64) float64

GaussRange returns a random number within a normal distribution (mostly) within a minVal/maxVal range.

func Halton added in v0.7.2

func Halton(base, index int) float64

Halton returns a quasirandom number from the Halton sequence.

func HaltonSequence added in v0.7.2

func HaltonSequence(base, start, count int) []float64

HaltonSequence returns a slice of floats from the Halton sequence, starting at start.

func Int

func Int() int

Int returns a random integer.

func IntArray

func IntArray(size int, minVal, maxVal int) []int

IntArray returns an array of a given size filled with random int from minVal to maxVal.

func IntRange

func IntRange(minVal int, maxVal int) int

IntRange returns a random int from minVal to maxVal.

func Norm

func Norm(mean, std float64) float64

Norm returns a random number within a normal distribution with the given mean and standard deviation.

func Power

func Power(minVal, maxVal, power float64) float64

Power returns a random number raised to a power.

func RandSeed

func RandSeed()

RandSeed seeds the prng with a random seed.

func Seed

func Seed(seed uint64)

Seed sets the prng seed.

func Sign

func Sign() float64

Sign returns either -1.0 or 1.0 with equal distribution.

func String

func String(length int) string

String returns a random string.

func StringAlpha

func StringAlpha(length int) string

StringAlpha returns a random string of letters.

func StringLower

func StringLower(length int) string

StringLower returns a random lower case string.

func StringUpper

func StringUpper(length int) string

StringUpper returns a random upper case string.

func WeightedBool

func WeightedBool(weight float64) bool

WeightedBool returns a weighted boolean.

Types

type Random

type Random struct {
	// contains filtered or unexported fields
}

Random represents a single unique PRNG

func NewRandom

func NewRandom() *Random

NewRandom creates a new Random instance.

func (*Random) Angle

func (r *Random) Angle() float64

Angle returns a random angle from 0 to 2PI radians.

func (*Random) Boolean

func (r *Random) Boolean() bool

Boolean returns a random boolean.

func (Random) Complex

func (r Random) Complex() complex128

Complex returns a random complex number from -1 + -1i to 1 + 1i

func (Random) ComplexRange

func (r Random) ComplexRange(realMin, realMax, imagMin, imagMax float64) complex128

ComplexRange returns a random complex number in the given ranges.

func (*Random) Float

func (r *Random) Float() float64

Float returns a random float from 0.0 to 1.0.

func (*Random) FloatArray

func (r *Random) FloatArray(size int, minVal, maxVal float64) []float64

FloatArray returns an array of a given size filled with random floats from minVal to maxVal.

func (*Random) FloatRange

func (r *Random) FloatRange(minVal float64, maxVal float64) float64

FloatRange returns a random float from minVal to maxVal.

func (*Random) GaussRange

func (r *Random) GaussRange(minVal, maxVal float64) float64

GaussRange returns a random number within a normal distribution (mostly) within a minVal/maxVal range.

func (*Random) Int

func (r *Random) Int() int

Int returns a random integer.

func (*Random) IntArray

func (r *Random) IntArray(size int, minVal, maxVal int) []int

IntArray returns an array of a given size filled with random int from minVal to maxVal.

func (*Random) IntRange

func (r *Random) IntRange(minVal int, maxVal int) int

IntRange returns a random int from minVal to maxVal.

func (*Random) Norm

func (r *Random) Norm(mean, std float64) float64

Norm returns a random number within a normal distribution with the given mean and standard deviation.

func (*Random) Power

func (r *Random) Power(minVal, maxVal, power float64) float64

Power returns a random number between minVal and maxVal. The higher the power, the more the result will be skewed towards minVal.

func (*Random) RandSeed

func (r *Random) RandSeed()

RandSeed seeds the prng with a random seed.

func (*Random) Seed

func (r *Random) Seed(seed uint64)

Seed sets the prng seed.

func (*Random) Sign

func (r *Random) Sign() float64

Sign returns either -1.0 or 1.0 with equal distribution.

func (*Random) String

func (r *Random) String(length int) string

String returns a random string.

func (*Random) StringAlpha

func (r *Random) StringAlpha(length int) string

StringAlpha returns a random string of letters.

func (*Random) StringFrom

func (r *Random) StringFrom(length int, chars string) string

StringFrom returns a random string of characters from the source string.

func (*Random) StringLower

func (r *Random) StringLower(length int) string

StringLower returns a random lower case string.

func (*Random) StringUpper

func (r *Random) StringUpper(length int) string

StringUpper returns a random upper case string.

func (*Random) WeightedBool

func (r *Random) WeightedBool(weight float64) bool

WeightedBool returns a weighted boolean.

func (Random) WeightedIndex

func (r Random) WeightedIndex(weights []float64) int

WeightedIndex returns a random int based on an array of weights.

Jump to

Keyboard shortcuts

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