rand

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: AGPL-3.0 Imports: 16 Imported by: 13

Documentation

Overview

Package rand provides various utitilies related to generating cryptographically secure random numbers and byte vectors.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Reader is a replacement for crypto/rand.Reader.
	Reader io.Reader
)

Functions

func Exp

func Exp(r *rand.Rand, lambda float64) float64

Exp returns a random sample from the exponential distribution characterized by lambda (inverse of the mean).

func ExpQuantile

func ExpQuantile(lambda, p float64) float64

ExpQuantile returns the value at which the the probability of a random value is less than or equal to the given probability for an exponential distribution characterized by lambda.

func NewMath

func NewMath() *rand.Rand

NewMath returns a "cryptographically secure" math/rand.Rand.

func Poisson

func Poisson(r *rand.Rand, lambda float64) int

Poisson returns a random sample from the poisson distribution characterized by lambda (mean).

Types

type DeterministicRandReader

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

DeterministicRandReader is a random Reader whose output is a chacha20 keystream.

func NewDeterministicRandReader

func NewDeterministicRandReader(key []byte) (*DeterministicRandReader, error)

NewDeterministicRandReader returns a DeterministicRandReader initialized with key.

func (*DeterministicRandReader) Int63

func (r *DeterministicRandReader) Int63() int64

Int63 returns a random int64 with most significant bit set to 0.

func (*DeterministicRandReader) Perm

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

Perm returns the shuffled slice of integers from 0 to n.

func (*DeterministicRandReader) Read

func (r *DeterministicRandReader) Read(data []byte) (int, error)

Read writes the keystream into the passed byteslice and returns the number of bytes written.

func (*DeterministicRandReader) Seed

func (r *DeterministicRandReader) Seed(seed int64)

Seed initializes the DeterministicRandReader with nonce.

Jump to

Keyboard shortcuts

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