randutil

package
v0.0.0-...-c7fba9c Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2021 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package randutil initialises properly random value generation and exposes a streamlined set of functions for it, including for crypto random tokens.

Index

Constants

This section is empty.

Variables

View Source
var (
	Intn   = rand.Intn
	Int63n = rand.Int63n
)

Re-exported from math/rand for streamlining.

Functions

func CryptoToken

func CryptoToken(nbytes int) (string, error)

CryptoToken returns a crypthographically secure token string encoding nbytes random bytes. The result is URL-safe.

func CryptoTokenBytes

func CryptoTokenBytes(nbytes int) ([]byte, error)

CryptoTokenBytes returns a crypthographically secure token of nbytes random bytes.

func RandomDuration

func RandomDuration(d time.Duration) time.Duration

RandomDuration returns a random duration up to the given length.

func RandomKernelUUID

func RandomKernelUUID() string

RandomKernelUUID will return a UUID from the kernel's procfs API at /proc/sys/kernel/random/uuid. Only to be used in very specific uses, most random code should use CryptoToken(Bytes) instead.

func RandomString

func RandomString(length int) string

RandomString returns a random string of length length.

The vowels are omitted to avoid that words are created by pure chance. Numbers are included.

Not cryptographically secure.

Types

This section is empty.

Jump to

Keyboard shortcuts

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