fastrand

package
v2.14.7 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Float64

func Float64() float64

Float64 returns, as a float64, a pseudo-random number in the half-open interval [0.0,1.0).

func Int

func Int() int

Int returns a non-negative pseudo-random int from the default Source.

func Int32 added in v2.12.0

func Int32() int32

Int32 returns a non-negative pseudo-random 31-bit integer as an int32.

func Int64 added in v2.12.0

func Int64() int64

Int64 returns a non-negative pseudo-random 63-bit integer as an int64.

func N added in v2.12.0

func N[Int constraints.Integer](n Int) Int

N returns a pseudo-random number in the half-open interval [0,n) from the default Source. The type parameter Int can be any integer type. It panics if n <= 0.

func Perm

func Perm(n int) []int

Perm returns, as a slice of n ints, a pseudo-random permutation of the integers in the half-open interval [0,n).

func Shuffle

func Shuffle(n int, swap func(i, j int))

Shuffle pseudo-randomizes the order of elements. n is the number of elements. Shuffle panics if n < 0. swap swaps the elements with indexes i and j.

func Uint32

func Uint32() uint32

Uint32 returns a pseudo-random 32-bit value as a uint32.

func Uint64

func Uint64() (x uint64)

Uint64 returns a pseudo-random 64-bit value as a uint64.

Types

type Rand added in v2.12.0

type Rand struct {
	// contains filtered or unexported fields
}

A Rand is a source of random numbers.

func New added in v2.12.0

func New(src Source) *Rand

New returns a new Rand that uses random values from src to generate other random values.

func NewPCG added in v2.12.0

func NewPCG(seed1, seed2 uint64) *Rand

NewPCG returns a new PCG generator seeded with the given values.

func (*Rand) Float64 added in v2.12.0

func (r *Rand) Float64() float64

Float64 returns, as a float64, a pseudo-random number in the half-open interval [0.0,1.0).

func (*Rand) Int added in v2.12.3

func (r *Rand) Int() int

Int returns a non-negative pseudo-random int.

func (*Rand) Int32 added in v2.12.0

func (r *Rand) Int32() int32

Int32 returns a non-negative pseudo-random 31-bit integer as an int32.

func (*Rand) Int64 added in v2.12.0

func (r *Rand) Int64() int64

Int64 returns a non-negative pseudo-random 63-bit integer as an int64.

func (*Rand) Perm added in v2.12.0

func (r *Rand) Perm(n int) []int

Perm returns, as a slice of n ints, a pseudo-random permutation of the integers in the half-open interval [0,n).

func (*Rand) Shuffle added in v2.12.0

func (r *Rand) Shuffle(n int, swap func(i, j int))

Shuffle pseudo-randomizes the order of elements. n is the number of elements. Shuffle panics if n < 0. swap swaps the elements with indexes i and j.

func (*Rand) Uint32 added in v2.12.0

func (r *Rand) Uint32() uint32

Uint32 returns a pseudo-random 32-bit value as a uint32.

func (*Rand) Uint64 added in v2.12.0

func (r *Rand) Uint64() uint64

Uint64 returns a pseudo-random 64-bit value as a uint64.

func (*Rand) Uint64N added in v2.12.3

func (r *Rand) Uint64N(n uint64) uint64

Uint64N returns, as an uint64, a non-negative pseudo-random number in the half-open interval [0,n). It panics if n == 0.

type Source added in v2.12.0

type Source interface {
	Uint64() uint64
}

A Source is a source of uniformly-distributed pseudo-random uint64 values in the range [0, 1<<64).

A Source is not safe for concurrent use by multiple goroutines.

Jump to

Keyboard shortcuts

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