xrand

package
v2.6.6 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 2 Imported by: 2

Documentation

Index

Constants

View Source
const (
	LetterSeed           = rand.LetterSeed           // Letters in both upper and lower case
	LetterLowerSeed      = rand.LetterLowerSeed      // Lower-case letters
	LetterUpperSeed      = rand.LetterUpperSeed      // Upper-case letters
	DigitSeed            = rand.DigitSeed            // Digits
	DigitWithoutZeroSeed = rand.DigitWithoutZeroSeed // Digits without zero
	SymbolSeed           = rand.SymbolSeed           // Special symbols
)

Variables

This section is empty.

Functions

func Digits

func Digits(length int, hasLeadingZero ...bool) string

Digits returns a string of the given length made of digits. The optional hasLeadingZero reports whether the string may start with zero.

func Duration added in v2.3.1

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

Duration returns a time interval in [min, max].

func ExpFloat64 added in v2.6.0

func ExpFloat64() float64

ExpFloat64 returns a 64-bit float drawn from an exponential distribution with rate parameter (lambda) 1 and mean 1.

func Float32

func Float32() float32

Float32 returns a pseudo-random 32-bit float in [0.0, 1.0).

func Float32R added in v2.6.0

func Float32R(min, max float32) float32

Float32R returns a 32-bit float in [min, max).

func Float64

func Float64() float64

Float64 returns a pseudo-random 64-bit float in [0.0, 1.0).

func Float64R added in v2.6.0

func Float64R(min, max float64) float64

Float64R returns a 64-bit float in [min, max).

func Int

func Int() int

Int returns a non-negative pseudo-random integer.

func Int32

func Int32() int32

Int32 returns a non-negative pseudo-random 31-bit integer.

func Int32N added in v2.6.0

func Int32N(n int32) int32

Int32N returns a non-negative pseudo-random 32-bit integer in [0, n). n must be greater than 0.

func Int32R added in v2.6.0

func Int32R(min, max int32) int32

Int32R returns a 32-bit integer in [min, max].

func Int64N added in v2.6.0

func Int64N(n int64) int64

Int64N returns a non-negative pseudo-random 64-bit integer in [0, n). n must be greater than 0.

func Int64R added in v2.6.0

func Int64R(min, max int64) int64

Int64R returns a 64-bit integer in [min, max].

func IntN added in v2.6.0

func IntN(n int) int

IntN returns a non-negative pseudo-random integer in [0, n). n must be greater than 0.

func IntR added in v2.6.0

func IntR(min, max int) int

IntR returns an integer in [min, max].

func Letters

func Letters(length int) string

Letters returns a string of the given length made of letters.

func Lucky

func Lucky(probability float64, base ...float64) bool

Lucky reports whether a lucky draw with the given probability hits. The optional base is the probability denominator and defaults to 100.

func NormFloat64 added in v2.6.0

func NormFloat64() float64

NormFloat64 returns a 64-bit float drawn from the standard normal distribution, with mean 0 and standard deviation 1.

func Perm added in v2.6.0

func Perm(n int) []int

Perm returns a pseudo-random permutation of the integers in [0, n).

func Shuffle added in v2.1.0

func Shuffle[T any](list []T)

Shuffle randomly reorders list in place.

func Str

func Str(seed string, length int) string

Str returns a string of the given length built from the characters of seed.

func Symbols

func Symbols(length int) string

Symbols returns a string of the given length made of special characters.

func Uint added in v2.6.0

func Uint() uint

Uint returns a pseudo-random unsigned integer.

func Uint32 added in v2.6.0

func Uint32() uint32

Uint32 returns a pseudo-random 32-bit unsigned integer.

func Uint32N added in v2.6.0

func Uint32N(n uint32) uint32

Uint32N returns a non-negative pseudo-random 32-bit unsigned integer in [0, n). n must be greater than 0.

func Uint64 added in v2.6.0

func Uint64() uint64

Uint64 returns a pseudo-random 64-bit unsigned integer.

func Uint64N added in v2.6.0

func Uint64N(n uint64) uint64

Uint64N returns a non-negative pseudo-random 64-bit unsigned integer in [0, n). n must be greater than 0.

func UintN added in v2.6.0

func UintN(n uint) uint

UintN returns a non-negative pseudo-random unsigned integer in [0, n). n must be greater than 0.

func Weight

func Weight[T any](fn func(v T) float64, list ...T) (int, T, bool)

Weight performs a weighted random selection over list, where fn returns the weight of an item. It returns false when the total weight is invalid (<= 0).

On success it returns the index of the selected item, the item itself and true. When nothing is selected it returns -1, the zero value of T and false.

Types

This section is empty.

Jump to

Keyboard shortcuts

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