rand2

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// See math/rand for documentation.
	New = rand.New

	// See math/rand for documentation.
	Seed = rand.New

	// See math/rand for documentation.
	Int63 = rand.Int63

	// See math/rand for documentation.
	Uint32 = rand.Uint32

	// See math/rand for documentation.
	Int31 = rand.Int31

	// See math/rand for documentation.
	Int = rand.Int

	// See math/rand for documentation.
	Int63n = rand.Int63n

	// See math/rand for documentation.
	Int31n = rand.Int31n

	// See math/rand for documentation.
	Intn = rand.Intn

	// See math/rand for documentation.
	Float64 = rand.Float64

	// See math/rand for documentation.
	Float32 = rand.Float32

	// See math/rand for documentation.
	Perm = rand.Perm

	// See math/rand for documentation.
	NormFloat64 = rand.NormFloat64

	// See math/rand for documentation.
	ExpFloat64 = rand.ExpFloat64

	// See math/rand for documentation.
	NewZipf = rand.NewZipf
)

Functions

func Dur

func Dur(max time.Duration) time.Duration

Dur returns a pseudo-random Duration in [0, max)

func GetSeed

func GetSeed() int64

Generates a seed based on the current time and the process ID.

func Jitter

func Jitter(period time.Duration) time.Duration

Uniformly jitters the provided duration by +/- 50%.

func JitterFraction

func JitterFraction(period time.Duration, fraction float64) time.Duration

Uniformly jitters the provided duration by +/- the given fraction. NOTE: fraction must be in (0, 1].

func NewSource

func NewSource(seed int64) rand.Source

This returns a thread-safe random source.

func PickN

func PickN(population []interface{}, n int) (
	picked []interface{}, remaining []interface{}, err error,
)

Same as 'Sample' except it returns both the 'picked' sample set and the 'remaining' elements.

func Sample

func Sample(population []interface{}, k int) (res []interface{}, err error)

Samples 'k' elements from the given slice

func SampleInts

func SampleInts(n int, k int) (res []int, err error)

Samples 'k' unique ints from the range [0, n)

func Shuffle

func Shuffle(collection Swapper)

Randomly shuffles the collection in place.

Types

type Swapper

type Swapper interface {
	// Len is the number of elements in the collection.
	Len() int
	// Swap swaps the elements with indexes i and j.
	Swap(i int, j int)
}

A subset of sort.Interface used for random shuffle.

Jump to

Keyboard shortcuts

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