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 Rand
- func (r *Rand) AdjectiveNoun() string
- func (r *Rand) Bool() bool
- func (r *Rand) DurationRange(low, high time.Duration) time.Duration
- func (r *Rand) Float32() float32
- func (r *Rand) Float32Range(low, high float32) float32
- func (r *Rand) Int31n(n int32) int32
- func (r *Rand) IntRange(low, high int) int
- func (r *Rand) Intn(n int) int
- func (r *Rand) MarshalBinary() ([]byte, error)
- func (r *Rand) MarshalJSON() ([]byte, error)
- func (r *Rand) MarshalMsgpack() ([]byte, error)
- func (r *Rand) Seed(s uint64)
- func (r *Rand) Uint32() uint32
- func (r *Rand) UnmarshalBinary(data []byte) error
- func (r *Rand) UnmarshalJSON(b []byte) error
- func (r *Rand) UnmarshalMsgpack(b []byte) error
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 ¶
type Rand ¶
type Rand struct {
// contains filtered or unexported fields
}
Rand wraps math/rand/v2's PCG generator and provides project-specific helpers (inclusive ranges, sampling, weighted sampling, etc.) that the stdlib does not. State serializes via PCG.MarshalBinary; we expose it as JSON and msgpack so a *Rand can ride along inside the persisted Sim.