rand

package
v0.30.3-archive-node Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: AGPL-3.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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