Documentation
      ¶
    
    
  
    
  
    Overview ¶
Package random contains various methods for creating random values.
Package random contains various methods for creating random values.
Index ¶
- func Angle() float64
 - func Around(val, amt float64) float64
 - func Bit() int
 - func Boolean() bool
 - func Byte() byte
 - func Element[T any](list []T) T
 - func Float() float64
 - func FloatArray(size int, minVal, maxVal float64) []float64
 - func FloatRange(minVal float64, maxVal float64) float64
 - func GaussRange(minVal, maxVal float64) float64
 - func Halton(base, index int) float64
 - func HaltonSequence(base, start, count int) []float64
 - func Int() int
 - func IntArray(size int, minVal, maxVal int) []int
 - func IntRange(minVal int, maxVal int) int
 - func Norm(mean, std float64) float64
 - func Power(minVal, maxVal, power float64) float64
 - func RandSeed()
 - func Seed(seed uint64)
 - func Sign() float64
 - func String(length int) string
 - func StringAlpha(length int) string
 - func StringLower(length int) string
 - func StringUpper(length int) string
 - func WeightedBool(weight float64) bool
 - type Random
 - func (r *Random) Angle() float64
 - func (r *Random) Boolean() bool
 - func (r Random) Complex() complex128
 - func (r Random) ComplexRange(realMin, realMax, imagMin, imagMax float64) complex128
 - func (r *Random) Float() float64
 - func (r *Random) FloatArray(size int, minVal, maxVal float64) []float64
 - func (r *Random) FloatRange(minVal float64, maxVal float64) float64
 - func (r *Random) GaussRange(minVal, maxVal float64) float64
 - func (r *Random) Int() int
 - func (r *Random) IntArray(size int, minVal, maxVal int) []int
 - func (r *Random) IntRange(minVal int, maxVal int) int
 - func (r *Random) Norm(mean, std float64) float64
 - func (r *Random) Power(minVal, maxVal, power float64) float64
 - func (r *Random) RandSeed()
 - func (r *Random) Seed(seed uint64)
 - func (r *Random) Sign() float64
 - func (r *Random) String(length int) string
 - func (r *Random) StringAlpha(length int) string
 - func (r *Random) StringFrom(length int, chars string) string
 - func (r *Random) StringLower(length int) string
 - func (r *Random) StringUpper(length int) string
 - func (r *Random) WeightedBool(weight float64) bool
 - func (r Random) WeightedIndex(weights []float64) int
 
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Around ¶
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 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 FloatArray ¶
FloatArray returns an array of a given size filled with random floats from minVal to maxVal.
func FloatRange ¶
FloatRange returns a random float from minVal to maxVal.
func GaussRange ¶
GaussRange returns a random number within a normal distribution (mostly) within a minVal/maxVal range.
func HaltonSequence ¶ added in v0.7.2
HaltonSequence returns a slice of floats from the Halton sequence, starting at start.
func IntArray ¶
IntArray returns an array of a given size filled with random int from minVal to maxVal.
func Norm ¶
Norm returns a random number within a normal distribution with the given mean and standard deviation.
func StringAlpha ¶
StringAlpha returns a random string of letters.
func StringLower ¶
StringLower returns a random lower case string.
func StringUpper ¶
StringUpper returns a random upper case string.
Types ¶
type Random ¶
type Random struct {
	// contains filtered or unexported fields
}
    Random represents a single unique PRNG
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) FloatArray ¶
FloatArray returns an array of a given size filled with random floats from minVal to maxVal.
func (*Random) FloatRange ¶
FloatRange returns a random float from minVal to maxVal.
func (*Random) GaussRange ¶
GaussRange returns a random number within a normal distribution (mostly) within a minVal/maxVal range.
func (*Random) IntArray ¶
IntArray returns an array of a given size filled with random int from minVal to maxVal.
func (*Random) Norm ¶
Norm returns a random number within a normal distribution with the given mean and standard deviation.
func (*Random) Power ¶
Power returns a random number between minVal and maxVal. The higher the power, the more the result will be skewed towards minVal.
func (*Random) StringAlpha ¶
StringAlpha returns a random string of letters.
func (*Random) StringFrom ¶
StringFrom returns a random string of characters from the source string.
func (*Random) StringLower ¶
StringLower returns a random lower case string.
func (*Random) StringUpper ¶
StringUpper returns a random upper case string.
func (*Random) WeightedBool ¶
WeightedBool returns a weighted boolean.
func (Random) WeightedIndex ¶
WeightedIndex returns a random int based on an array of weights.