random

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package random provides cryptographically secure random helpers.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidLength = errors.New("random: length must be non-negative")

ErrInvalidLength is returned when a requested length is negative.

Functions

func Bytes

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

Bytes returns n cryptographically random bytes.

func MustToken

func MustToken(n int) string

MustToken returns n random hex characters and panics if the CSPRNG fails or n is negative. Intended for request IDs where failure is unrecoverable.

func NumCode

func NumCode() (string, error)

NumCode returns a cryptographically random six-digit numeric string.

func Shuffle

func Shuffle[T any](sli []T)

Shuffle permutes sli in place using the auto-seeded math/rand/v2 generator. It is NOT cryptographically secure; do not use it for secrets.

func UUID

func UUID() (string, error)

UUID returns 32 lowercase hex characters (128 random bits).

func UUIDWithLen

func UUIDWithLen(n int) (string, error)

UUIDWithLen returns exactly n lowercase hex characters from the CSPRNG.

Types

This section is empty.

Jump to

Keyboard shortcuts

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