erand

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChooseKInPlace

func ChooseKInPlace[T any](rng interface{ Intn(int) int }, a []T, k int) []T

ChooseKInPlace chooses N elements from the sample without replacement. This modifies the original slice and hands back a _sub-slice_. If this isn't what you want, copy the slice first.

func ChooseKWithReplacement

func ChooseKWithReplacement[T any](rng *rand.Rand, bag []T, k int) []T

ChooseKWithReplacement chooses k not-necessarially-distinct elements from a bag of items.

func FillSliceRaw

func FillSliceRaw[T any](dst []T, rng rand.Source64)

FillSliceRaw fills the slice with randomly generated values of T. This is not safe for all types: see NewRaw.

func NewRNG

func NewRNG() *rand.Rand

NewRNG creates a new, NON-thread-safe, NON-cryptographically seucre rng, initializing the seed via crypto/rand.Int.

func NewRaw

func NewRaw[T any](rng rand.Source64) (t T)

NewRaw generates a random element of T from completely random bits. This is only defined for the following types: non-string primitives, primitive integers, floats, complex numbers, booleans, and arrays and structs (recursively) comprised of those types. Floats and Complex numbers may not give a USEFUL result: subnormal numbers, NaNs, and +/- infinity may all result. That is, the following types are OK: int8..=int64, uint8..=uint64, bool, []int8..=int64, struct{x, y, z int}, [20]struct{x, y, z int}

func PopRandom

func PopRandom[T any](rng interface{ Intn(int) int }, a []T) (remaining []T, popped T)

Pop a random element from the slice. Panics if the slice is empty.

func SliceOf

func SliceOf[T any](rng rand.Source64, len int) []T

SliceOf generates a random slice of length n filled with random numbers.

func UpperAlphanumericString

func UpperAlphanumericString(rng *rand.Rand, n int) string

UpperAlphanumericString generates string of len-n from the characters [A-Z0-9], chosen at random.

Types

This section is empty.

Jump to

Keyboard shortcuts

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