rand

package
v1.3.0 Latest Latest
Warning

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

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

README

rand

随机工具:随机字符串、整数、字节切片、随机选择、洗牌。

安装

import "github.com/Ccmuyu/gopkg/rand"

快速开始

rand.String(16)                          // "aB3xK9mQ..."
rand.Int(1, 100)                         // 42
rand.Bytes(32)                           // []byte (crypto/rand)
rand.Choice([]string{"a", "b", "c"})     // "a" (随机)
rand.Shuffle([]int{1, 2, 3, 4, 5})       // 原地洗牌

API 参考

func String(n int) string
func Int(min, max int) int
func Bytes(n int) []byte
func Choice[T any](slice []T) T
func Shuffle[T any](slice []T)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes

func Bytes(n int) []byte

func Choice

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

func Int

func Int(min, max int) int

func Shuffle

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

func String

func String(n int) string

String 返回长度为 n 的随机字母数字字符串。 注意:基于 math/rand,非加密安全,切勿用于生成密钥/令牌/密码; 此类场景请使用 crypto.RandomToken。

Types

This section is empty.

Jump to

Keyboard shortcuts

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