rand

package
v0.30.3-fix-event-stre... Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Samples

func Samples(n uint, m uint, swap func(i, j uint)) error

Samples picks randomly m elements out of n elemnts in a data structure and places them in random order at indices [0,m-1], the swapping being implemented in place. The data structure is defined by the `swap` function. Sampling is not deterministic.

It implements the first (m) elements of Fisher-Yates Shuffle using crypto/rand as a source of randoms.

O(1) space and O(m) time

func Shuffle

func Shuffle(n uint, swap func(i, j uint)) error

Shuffle permutes a data structure in place based on the provided `swap` function. It is not deterministic.

It implements Fisher-Yates Shuffle using crypto/rand as a source of randoms.

O(1) space and O(n) time

func Uint

func Uint() (uint, error)

returns a random uint

func Uint32

func Uint32() (uint32, error)

returns a random uint32

func Uint32n

func Uint32n(n uint32) (uint32, error)

returns a random uint32 strictly less than n errors if n==0

func Uint64

func Uint64() (uint64, error)

returns a random uint64

func Uint64n

func Uint64n(n uint64) (uint64, error)

returns a random uint64 strictly less than n errors if n==0

func Uintn

func Uintn(n uint) (uint, error)

returns a random uint strictly less than n errors if n==0

Types

This section is empty.

Jump to

Keyboard shortcuts

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