rand

package
v0.0.0-...-37b37ea Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package rand provides cryptographically secure random number generation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidLength is returned when requested length is invalid
	ErrInvalidLength = errors.New("invalid length: must be positive")

	// ErrNilMax is returned when max parameter is nil
	ErrNilMax = errors.New("max cannot be nil")

	// ErrInvalidMax is returned when max is not positive
	ErrInvalidMax = errors.New("max must be positive")

	// ErrInvalidRange is returned when range parameters are invalid
	ErrInvalidRange = errors.New("invalid range: min must be less than max")

	// ErrInvalidBitSize is returned when bit size is too small
	ErrInvalidBitSize = errors.New("bit size must be at least 2")
)

Reader is the default cryptographically secure random number generator

Functions

func GenerateNonce

func GenerateNonce(length int) ([]byte, error)

GenerateNonce generates a cryptographically secure nonce of specified length

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes generates n cryptographically secure random bytes

func GenerateRandomInt

func GenerateRandomInt(min, max int) (int, error)

GenerateRandomInt generates a random integer in range [min, max)

func GenerateRandomPrime

func GenerateRandomPrime(bits int) (*big.Int, error)

GenerateRandomPrime generates a random prime of the specified bit size

func GenerateRandomScalar

func GenerateRandomScalar(max *big.Int) (*big.Int, error)

GenerateRandomScalar generates a random scalar in range [1, max) This is cryptographically secure and uniform

func Shuffle

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

Shuffle performs a cryptographically secure Fisher-Yates shuffle

Types

This section is empty.

Jump to

Keyboard shortcuts

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