randx

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package randx contains randomization functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SecureString added in v0.1.6

func SecureString(n int, alphabet []rune) string

SecureString returns a string of length n, composed of random characters from the provided alphabet, generated from a secure RNG. If the input slice is nil, returns a random mixed case alphanumeric string.

func String

func String(n int, alphabet []rune) string

String returns a string of length n, composed of random characters from the provided alphabet. If the input slice is nil, returns a random mixed case alphanumeric string.

Types

type Rand

type Rand interface {
	StringRand

	Int() int
	Intn(n int) int
	Int31() int32
	Int31n(n int32) int32
	Int63() int64
	Int63n(n int64) int64
	Float32() float32
	Float64() float64
	Read(p []byte) (n int, err error)
}

Rand can generate random values of various types.

func New

func New(src rand.Source) Rand

New creates a new RNG around a given source.

type StringRand added in v0.1.6

type StringRand interface {
	String(n int, alphabet []rune) string
}

StringRand can generate random strings for an alphabet. Supports both math/rand and crypto/rand.

var (
	SecureStringRand StringRand = NewSecureStringRand(cryptrand.Reader)
)

SecureStringRand is a StringRand that uses a secure RNG.

func NewSecureStringRand added in v0.1.6

func NewSecureStringRand(r io.Reader) StringRand

NewSecureStringRand returns a StringRand that uses a secure RNG.

Jump to

Keyboard shortcuts

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