fastrand

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: MIT Imports: 4 Imported by: 2

README

Fastrand

License GoDev Reference Go Report Card

Package fastrand provides quickly generated pseudo-random numbers with no repeatability guarantees on the stream of values.

It uses internals of the go runtime to generate pseudo-random numbers without requiring mutexes or syncronization. As a result, it's much faster than math/rand and scales very well to many cores. It doesn't allow you to provide your own seed or generate a stable sequence of values.

Documentation

Overview

Package fastrand provides quickly generated pseudo-random numbers with no repeatability guarantees on the stream of values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fill

func Fill(p []byte)

Fill fills b with pseudo-random bytes.

func Float32

func Float32() float32

Float32 returns a pseudo-random float32 in the half-open interval [0,n).

func Float64

func Float64() float64

Float64 returns a pseudo-random float64 in the half-open interval [0,n).

func Int31

func Int31() int32

Int31 returns a non-negative pseudo-random int32.

func Int31n

func Int31n(n int32) int32

Int31n returns a non-negative pseudo-random int32 in the half-open interval [0,n). It panics if n <= 0.

func Int63

func Int63() int64

Int63 returns a non-negative pseudo-random int64.

func Int63n

func Int63n(n int64) int64

Int63n returns a non-negative pseudo-random int64 in the half-open interval [0,n). It panics if n <= 0.

func Jitter added in v0.2.0

func Jitter[T Real](v T, factor float64) T

Jitter returns a pseudo-random value in the interval [v - factor*v, v + factor*v].

func NormFloat64

func NormFloat64() float64

NormFloat64 returns a normally distributed float64 in the range -math.MaxFloat64 through +math.MaxFloat64 inclusive, with standard normal distribution (mean = 0, stddev = 1). To produce a different normal distribution, callers can adjust the output using:

sample = NormFloat64() * desiredStdDev + desiredMean

func Reader

func Reader() io.Reader

Reader returns an io.Reader that fills the read buffer with pseudo-random bytes and never returns an error.

func Shuffle

func Shuffle[E any](s []E)

Shuffle pseudo-randomizes the order of elements in s.

func Uint32

func Uint32() uint32

Uint32 returns a pseudo-random uint32.

func Uint64

func Uint64() uint64

Uint64 returns a pseudo-random uint64.

func Uint64n

func Uint64n(n uint64) uint64

Uint64n returns a pseudo-random uint64 in the half-open interval [0,n).

func Uint64nUint32n

func Uint64nUint32n(n uint32) uint32

Uint32n returns a pseudo-random uint32 in the half-open interval [0,n).

Types

type Real added in v0.2.1

type Real interface {
	constraints.Signed | constraints.Unsigned
}

A Real is a real number.

Jump to

Keyboard shortcuts

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