random

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 字符集
	CharsetAlphaNum   = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	CharsetAlpha      = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	CharsetAlphaLower = "abcdefghijklmnopqrstuvwxyz"
	CharsetAlphaUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	CharsetNumeric    = "0123456789"
	CharsetHex        = "0123456789abcdef"
	CharsetSpecial    = "!@#$%^&*()_+-=[]{}|;':\",./<>?"
)

Variables

This section is empty.

Functions

func Alpha

func Alpha(length int) string

Alpha 生成随机字母字符串

func AlphaLower

func AlphaLower(length int) string

AlphaLower 生成随机小写字母字符串

func AlphaUpper

func AlphaUpper(length int) string

AlphaUpper 生成随机大写字母字符串

func Bool

func Bool() bool

Bool 生成随机布尔值

func Bytes

func Bytes(length int) []byte

Bytes 生成随机字节数组

func Float64

func Float64() float64

Float64 生成 [0.0, 1.0) 范围内的随机浮点数

func Float64Range

func Float64Range(min, max float64) float64

Float64Range 生成指定范围内的随机浮点数 [min, max)

func Hex

func Hex(length int) string

Hex 生成随机十六进制字符串

func Int

func Int(min, max int) int

Int 生成指定范围内的随机整数 [min, max]

func Int64

func Int64(min, max int64) int64

Int64 生成指定范围内的随机 int64 [min, max]

func Numeric

func Numeric(length int) string

Numeric 生成随机数字字符串

func Password

func Password(length int) string

Password 生成随机密码(包含大小写字母、数字和特殊字符)

func Pick

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

Pick 从切片中随机选择一个元素

func PickN

func PickN[T any](slice []T, n int) []T

PickN 从切片中随机选择 n 个元素(不重复)

func SecureBytes

func SecureBytes(length int) ([]byte, error)

SecureBytes 使用加密安全随机数生成字节数组

func SecureString

func SecureString(length int) (string, error)

SecureString 使用加密安全随机数生成字符串

func SecureStringWithCharset

func SecureStringWithCharset(length int, charset string) (string, error)

SecureStringWithCharset 使用加密安全随机数生成指定字符集的字符串

func Shuffle

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

Shuffle 随机打乱切片顺序

func String

func String(length int) string

String 生成指定长度的随机字符串(字母+数字)

func StringWithCharset

func StringWithCharset(length int, charset string) string

StringWithCharset 使用指定字符集生成随机字符串

func Token

func Token() string

Token 生成用于认证的安全令牌

func UUID

func UUID() string

UUID 生成 UUID v4

func UUIDShort

func UUIDShort() string

UUIDShort 生成不带横线的 UUID

func WeightedPick

func WeightedPick(weights []int) int

WeightedPick 根据权重随机选择

Types

This section is empty.

Jump to

Keyboard shortcuts

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