rand

package
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2024 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdjectiveNoun

func AdjectiveNoun() string

func Float32

func Float32() float32

func Int31n

func Int31n(n int32) int32

func Intn

func Intn(n int) int

func PermutationElement

func PermutationElement(i int, n int, p uint32) int

PermutationElement returns the ith element of a random permutation of the set of integers [0...,n-1]. i/n, p is hash, via Andrew Kensler

func Sample

func Sample[T any](t ...T) T

func SampleFiltered

func SampleFiltered[T any](slice []T, pred func(T) bool) int

SampleFiltered uniformly randomly samples a slice, returning the index of the sampled item, using provided predicate function to filter the items that may be sampled. An index of -1 is returned if the slice is empty or the predicate returns false for all items.

func SampleRateMap added in v0.11.2

func SampleRateMap[T comparable](rates map[T]int) (T, int)

SampleRateMap randomly samples elements from a map of some type T to a rate with probability proportional to the element's rate.

func SampleSlice

func SampleSlice[T any](slice []T) T

SampleSlice uniformly randomly samples an element of a non-empty slice.

func SampleWeighted

func SampleWeighted[T any](slice []T, weight func(T) int) int

SampleWeighted randomly samples an element from the given slice with the probability of choosing each element proportional to the value returned by the provided callback.

func Seed

func Seed(s int64)

Types

type Rand

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

func New

func New() Rand

func (*Rand) Float32

func (r *Rand) Float32() float32

func (*Rand) Int31n

func (r *Rand) Int31n(n int32) int32

func (*Rand) Intn

func (r *Rand) Intn(n int) int

func (*Rand) Seed

func (r *Rand) Seed(s int64)

Jump to

Keyboard shortcuts

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