random

package
v0.0.0-...-0fadc07 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IDLen = 16
)

Default ID length.

Variables

View Source
var (
	AlphaNum      = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
	LowerAlphaNum = []rune("abcdefghijklmnopqrstuvwxyz0123456789")
)

Handy alphabets.

Functions

This section is empty.

Types

type Random

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

Random provides random generation utilities.

func NewRandom

func NewRandom(reader io.Reader) *Random

NewRandom initializes a new Random.

func (*Random) GetAlphabet

func (r *Random) GetAlphabet(length int, alphabet []rune) (string, error)

GetAlphabet gets a random string of the given length (in runes) composed of the given alphabet. The alphabet must be between 2 and 256 unique runes long.

func (*Random) GetHex

func (r *Random) GetHex(length int) (string, error)

GetHex gets a hex-encoded random string of the given length (in digits).

func (*Random) GetID

func (r *Random) GetID() (string, error)

GetID calls GetAlphabet with sane default settings: 16-long, URL-safe lowercase, about 82 bits of entropy.

func (*Random) GetSecureBytes

func (r *Random) GetSecureBytes(length int) ([]byte, error)

GetSecureBytes returns a byte slice of cryptographically secure random numbers of the given "length"

func (*Random) MustGetAlphabet

func (r *Random) MustGetAlphabet(length int, alphabet []rune) string

MustGetAlphabet is like GetAlphabet but panics on error.

func (*Random) MustGetHex

func (r *Random) MustGetHex(length int) string

MustGetHex is like GetHex but panics on error.

func (*Random) MustGetID

func (r *Random) MustGetID() string

MustGetID is like GetID but panics on error.

func (*Random) MustGetSecureBytes

func (r *Random) MustGetSecureBytes(length int) []byte

MustGetSecureBytes is like GetSecureBytes but panics on error.

func (*Random) Read

func (r *Random) Read(buf []byte) (int, error)

Read implements the io.Reader interface, proxying requests to the underlying reader.

Jump to

Keyboard shortcuts

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