random

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 4 Imported by: 12

Documentation

Overview

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 Boolean

func Boolean() bool

Boolean returns a random boolean.

func Float

func Float() float64

Float returns a random float from 0.0 to 1.0.

func FloatArray

func FloatArray(size int, min, max float64) []float64

FloatArray returns an array of a given size filled with random floats from min to max.

func FloatRange

func FloatRange(min float64, max float64) float64

FloatRange returns a random float from min to max.

func GaussRange

func GaussRange(min, max float64) float64

GaussRange returns a random number within a normal distribution (mostly) within a min/max range.

func Int

func Int() int

Int returns a random integer.

func IntArray

func IntArray(size int, min, max int) []int

IntArray returns an array of a given size filled with random int from min to max.

func IntRange

func IntRange(min int, max int) int

IntRange returns a random int from min to max.

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(min, max, power float64) float64

Power returns a random number raised to a power.

func RandSeed

func RandSeed() int64

RandSeed seeds the prng with a random seed.

func Seed

func Seed(seed int64)

Seed sets the prng seed.

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, min, max float64) []float64

FloatArray returns an array of a given size filled with random floats from min to max.

func (*Random) FloatRange

func (r *Random) FloatRange(min float64, max float64) float64

FloatRange returns a random float from min to max.

func (*Random) GaussRange

func (r *Random) GaussRange(min, max float64) float64

GaussRange returns a random number within a normal distribution (mostly) within a min/max range.

func (*Random) Int

func (r *Random) Int() int

Int returns a random integer.

func (*Random) IntArray

func (r *Random) IntArray(size int, min, max int) []int

IntArray returns an array of a given size filled with random int from min to max.

func (*Random) IntRange

func (r *Random) IntRange(min int, max int) int

IntRange returns a random int from min to max.

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(min, max, power float64) float64

Power returns a random number raised to a power.

func (*Random) RandSeed

func (r *Random) RandSeed() int64

RandSeed seeds the prng with a random seed.

func (*Random) Seed

func (r *Random) Seed(seed int64)

Seed sets the prng seed.

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