random

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alpha

func Alpha(n int) string

Alpha returns a random string of letters of length n includes both lowercase and uppercase letters

func Bool

func Bool() bool

Bool returns either true or false randomly

func Byte

func Byte() byte

Byte returns a single secure random byte [0,255]

func Choice

func Choice[T any](slice []T) T

Choice picks a random element from a non-empty slice Panics if the slice is empty.

func Date

func Date(min, max time.Time) time.Time

Date returns a random time.Time between min and max (inclusive) Safely swaps min and max

func Duration

func Duration(min, max time.Duration) time.Duration

Duration returns a random time.Duration between min and max (inclusive) Safely swaps min and max

func FromCharset

func FromCharset(n int, charset string) string

FromCharset returns a random string from your specific charset

func Number

func Number[T Num](min, max T) T

Number returns a random number in the range [min, max] inclusive for int and [min, max) for floats Safely swaps max & min Limitations: - uses math/rand (not safe for concurrent use, not for security-sensitive use) - overflow warning on extreme ranges

func Numeric

func Numeric(n int) string

Numeric returns a random string of digits of length n

func Password

func Password(n int, opts PasswordOptions) string

Password generates a random password of length n according to options. Panic if no charsets selected (or effectively not selected - e.g: excluding all options)

func Sign

func Sign() int

Sign returns either +1 or -1 randomly

func String

func String(n int) string

String returns a random alphanumeric string of length n includes both lowercase and uppercase letters

Types

type Num

type Num interface {
	~int | ~int64 | ~uint | ~float32 | ~float64
}

Num is a simple numeric constraint

type PasswordOptions

type PasswordOptions struct {
	Letters bool   // include a-zA-Z
	Digits  bool   // include 0-9
	Symbols bool   // include special characters
	Exclude string // any chars to exclude
}

PasswordOptions defines character sets for generating passwords

Jump to

Keyboard shortcuts

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