randutil

package
v0.4.13 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Utility package for random operations.

Index

Constants

View Source
const (
	DEFAULT_LEN = 35
)

Variables

This section is empty.

Functions

func ERand

func ERand(len int) string

Generate random string with high entrophy

func GenNo

func GenNo(prefix string) string

generate a random sequence number with specified prefix

func GenNoL

func GenNoL(prefix string, len int) string

generate a random sequence number with specified prefix

func Pick

func Pick(set []rune) rune

pick random rune from the slice

func RandAlpha

func RandAlpha(n int) string

Generate random alphabetic string with specified length

the generated string will contains [a-zA-Z]

func RandLowerAlpha

func RandLowerAlpha(n int) string

Generate random alphabetic, lowercase string with specified length

the generated string will contains [a-z]

func RandLowerAlphaNumeric

func RandLowerAlphaNumeric(n int) string

Generate random alphabetic, lowercase string with specified length

the generated string will contains [a-z0-9]

func RandLowerAlphaNumeric16

func RandLowerAlphaNumeric16() string

Same as RandLowerAlphaNumeric(16) but with less allocation.

func RandNum

func RandNum(n int) string

Generate random numeric string with specified length

the generated string will contains [0-9]

func RandOp

func RandOp(ops ...func())

invoke one of the funcs randomly

func RandPick

func RandPick[T any](s []T) T

func RandRune

func RandRune(n int, set []rune) string

generate randon str based on given length and given charset

func RandStr

func RandStr(n int) string

Generate random string with specified length

the generated string will contains [a-zA-Z0-9]

ERand() is preferred for higher entrophy

func RandUpperAlpha

func RandUpperAlpha(n int) string

Generate random alphabetic, uppercase string with specified length

the generated string will contains [A-Z]

func RandUpperAlphaNumeric

func RandUpperAlphaNumeric(n int) string

Generate random alphabetic, uppercase string with specified length

the generated string will contains [A-Z0-9]

func ShuffleRunes

func ShuffleRunes(letters []rune, times int) []rune

func ShuffleStr

func ShuffleStr(letters string, times int) string

func WeightedRandPick

func WeightedRandPick[T interface{ GetWeight() float64 }](s []T) T

Types

type WeightedItem

type WeightedItem[T any] struct {
	Value  T
	Weight float64
}

func (WeightedItem[T]) GetWeight

func (w WeightedItem[T]) GetWeight() float64

Jump to

Keyboard shortcuts

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