Documentation
¶
Index ¶
- func PermutationElement(i int, n int, p uint32) int
- func PermuteSlice[Slice ~[]E, E any](s Slice, seed uint32) iter.Seq2[int, E]
- func Sample[T any](r *Rand, t ...T) T
- func SampleFiltered[T any](r *Rand, slice []T, pred func(T) bool) int
- func SampleSeq[T any](r *Rand, it iter.Seq[T]) (sample T, ok bool)
- func SampleSlice[T any](r *Rand, slice []T) T
- func SampleWeighted[T any, W constraints.Integer | constraints.Float](r *Rand, slice []T, weight func(T) W) (T, bool)
- func SampleWeightedSeq[T any, W constraints.Integer | constraints.Float](r *Rand, it iter.Seq[T], weight func(T) W) (sample T, ok bool)
- func ShuffleSlice[Slice ~[]E, E any](s Slice, r *Rand)
- type PCG32
- type Rand
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PermutationElement ¶
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 SampleFiltered ¶
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 ¶
SampleSlice uniformly randomly samples an element of a non-empty slice.
func SampleWeighted ¶
func SampleWeighted[T any, W constraints.Integer | constraints.Float](r *Rand, slice []T, weight func(T) W) (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 ¶
func SampleWeightedSeq[T any, W constraints.Integer | constraints.Float](r *Rand, it iter.Seq[T], weight func(T) W) (sample T, ok bool)
func ShuffleSlice ¶
Types ¶
Click to show internal directories.
Click to hide internal directories.