randomness

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: BSD-2-Clause Imports: 7 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateModuloBias

func CalculateModuloBias(maxValue *big.Int, requiredBytes int) *big.Int

To remove modulo bias, we must calculate RAND_MAX - (RAND_MAX % N) Since we use a PRF that outputs a specific number of bytes (requiredBytes) RAND_MAX = ((2**(8*requiredBytes)) - 1) N = maxValue CalculateModuloBias returns those two values and returns the upper bound to avoid modulo bias

func GenerateSecureRandom

func GenerateSecureRandom(keySize int) ([]byte, error)

GenerateSecureRandom receives the number of desired randomness bytes and returns a slice of that size from Crypto.Rand

func PRF

func PRF(h hash.Hash, seed []byte) []byte

PRF is a pseudorandom function

func RandInInterval

func RandInInterval(max *big.Int, seed []byte, h hash.Hash) *big.Int

RandInInterval receives a seed and returns a random value (using a PRF) between [0, max-1]

func ReadRangeUint32

func ReadRangeUint32(start, end uint32, rng io.Reader) uint32

ReadRangeUint32 reduces a random integer from 0, MaxUint32 to greater than or equal to start and less than end

The reason start is inclusive and end is not is that this function is meant to work with lists (i.e., get random element inside the list, except for the first 3)

func ReadUint32

func ReadUint32(rng io.Reader) uint32

ReadUint32 reads an integer from an io.Reader (which should be a CSPRNG).

Types

This section is empty.

Jump to

Keyboard shortcuts

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