Documentation
¶
Index ¶
- Variables
- func MustSecureSlice[T ChoiceValue](length int, choices []T) []T
- func MustSecureString[T ~string](length int, choices T) string
- func SecureSlice[T ChoiceValue](length int, choices []T) ([]T, error)
- func SecureString[T ~string](length int, choices T) (string, error)
- func Uint64() uint64
- type ChoiceValue
- type Randomizer
- func (r *Randomizer[T]) Add(weight float64, result T) error
- func (r *Randomizer[T]) AddElement(element *RandomizerElement[T]) error
- func (r *Randomizer[T]) AddMany(elements []RandomizerElement[T]) error
- func (r *Randomizer[T]) MustSample() T
- func (r *Randomizer[T]) MustSampleMany(count int) []T
- func (r *Randomizer[T]) Prepare()
- func (r *Randomizer[T]) Sample() (T, error)
- func (r *Randomizer[T]) SampleMany(count int) ([]T, error)
- type RandomizerElement
Constants ¶
This section is empty.
Variables ¶
var SecureRng = rand.New(&cryptoRand{})
Functions ¶
func MustSecureSlice ¶
func MustSecureSlice[T ChoiceValue](length int, choices []T) []T
MustSecureSlice generates a random slice a given length and value choice set and ignore errors caused by the random source
func MustSecureString ¶
MustSecureString generates a random string of a given length and value choice set and ignore errors caused by the random source
func SecureSlice ¶
func SecureSlice[T ChoiceValue](length int, choices []T) ([]T, error)
SecureSlice generates a random slice of a given length and value choice set
func SecureString ¶
SecureString generates a random string of a given length and value choice set
Types ¶
type ChoiceValue ¶
type Randomizer ¶
type Randomizer[T any] struct { // contains filtered or unexported fields }
Randomizer is an implementation of the alias method
func NewRandomizer ¶
func NewRandomizer[T any]() *Randomizer[T]
NewRandomizer creates a Randomizer instance
func NewSecureRandomizer ¶
func NewSecureRandomizer[T any]() *Randomizer[T]
NewSecureRandomizer creates a Randomizer instance that uses a cryptographically secure source for random number and sample generation
func (*Randomizer[T]) Add ¶
func (r *Randomizer[T]) Add(weight float64, result T) error
Add adds elements to the Randomizer
func (*Randomizer[T]) AddElement ¶
func (r *Randomizer[T]) AddElement(element *RandomizerElement[T]) error
AddElement adds elements to the Randomizer
func (*Randomizer[T]) AddMany ¶
func (r *Randomizer[T]) AddMany(elements []RandomizerElement[T]) error
AddMany adds multiple elements to the Randomizer from an array of elements
func (*Randomizer[T]) MustSample ¶
func (r *Randomizer[T]) MustSample() T
MustSample samples the alias method to get a random value, respecting the weights of each element
func (*Randomizer[T]) MustSampleMany ¶
func (r *Randomizer[T]) MustSampleMany(count int) []T
MustSampleMany samples the alias method to get random values, respecting the weights of each element
func (*Randomizer[T]) Prepare ¶
func (r *Randomizer[T]) Prepare()
Prepare the randomizer for sampling
func (*Randomizer[T]) Sample ¶
func (r *Randomizer[T]) Sample() (T, error)
Sample the alias method to get a random value, respecting the weights of each element
func (*Randomizer[T]) SampleMany ¶
func (r *Randomizer[T]) SampleMany(count int) ([]T, error)
SampleMany samples the alias method to get random values, respecting the weights of each element
type RandomizerElement ¶
RandomizerElement is an element of a Randomizer