rand

package
v0.11.10 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2025 License: GPL-3.0 Imports: 4 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 PermuteSlice added in v0.11.8

func PermuteSlice[Slice ~[]E, E any](s Slice, seed uint32) iter.Seq2[int, E]

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 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) (T, bool)

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 SampleWeightedSeq added in v0.11.9

func SampleWeightedSeq[T any](it iter.Seq[T], weight func(T) int) (sample T, ok bool)

func Seed

func Seed(s int64)

func Uint32 added in v0.11.8

func Uint32() uint32

Types

type PCG32 added in v0.11.9

type PCG32 struct {
	State     uint64
	Increment uint64
}

func NewPCG32 added in v0.11.9

func NewPCG32() PCG32

func (*PCG32) Bounded added in v0.11.9

func (p *PCG32) Bounded(bound uint32) uint32

func (*PCG32) Random added in v0.11.9

func (p *PCG32) Random() uint32

func (*PCG32) Seed added in v0.11.9

func (p *PCG32) Seed(state, sequence uint64)

type Rand

type Rand struct {
	PCG32
}

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 uint64)

func (*Rand) Uint32 added in v0.11.8

func (r *Rand) Uint32() uint32

Jump to

Keyboard shortcuts

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