randx

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package randx provides random helper.

Index

Constants

This section is empty.

Variables

View Source
var (
	// AlphaNum contains runes [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789].
	AlphaNum = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
	// Alpha contains runes [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ].
	Alpha = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
	// AlphaLowerNum contains runes [abcdefghijklmnopqrstuvwxyz0123456789].
	AlphaLowerNum = []rune("abcdefghijklmnopqrstuvwxyz0123456789")
	// AlphaUpperNum contains runes [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789].
	AlphaUpperNum = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
	// AlphaLower contains runes [abcdefghijklmnopqrstuvwxyz].
	AlphaLower = []rune("abcdefghijklmnopqrstuvwxyz")
	// AlphaUpper contains runes [ABCDEFGHIJKLMNOPQRSTUVWXYZ].
	AlphaUpper = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
	// Numeric contains runes [0123456789].
	Numeric = []rune("0123456789")
)

Functions

func Int

func Int() (int, error)

Int returns a non-negative uniform random value as int.

func IntN

func IntN(max int) (int, error)

IntN returns a uniform random value in [0, max). It panics if max <= 0.

func MustNumeric

func MustNumeric(num int) int

MustNumeric returns a cryptographically secure random number in the range of [0, num).

func MustString

func MustString(l int, allowedRunes []rune) string

MustString returns a cryptographically secure random string sequence using the defined runes.

Panics on error.

func RuneSequence

func RuneSequence(l int, allowedRunes []rune) ([]rune, error)

RuneSequence returns a cryptographically secure random sequence using the defined allowed runes.

func Uint32

func Uint32() (uint32, error)

Uint32 returns a uniform random value as uint32.

func Uint32N

func Uint32N(max uint32) (uint32, error)

Uint32N returns a uniform random value in [0, max). It panics if max <= 0.

func Uint64

func Uint64() (uint64, error)

Uint64 returns a uniform random value as uint64.

func Uint64N

func Uint64N(max uint64) (uint64, error)

Uint64N returns a uniform random value in [0, max). It panics if max <= 0.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳