随机类

package
v0.0.0-...-2910145 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

包grand提供了高性能的随机字节/数字/字符串生成功能。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Meet

func Meet(num, total int) bool

Meet 随机计算给定的概率 `num`/`total` 是否满足条件。

func MeetProb

func MeetProb(prob float32) bool

MeetProb 随机计算给定概率是否满足。

func X从文本生成文本

func X从文本生成文本(给定文本 string, 长度 int) string

Str 从给定的字符串 `s` 中随机选取并返回 `n` 个字符。 它还支持Unicode字符串,如中文、俄文、日文等。

func X区间整数

func X区间整数(最小值, 最大值 int) int

N 返回一个在 min 和 max 范围内的随机整数:[min, max]。 其中 `min` 和 `max` 也支持负数。

func X字母文本

func X字母文本(长度 int) string

Letters 返回一个随机字符串,该字符串只包含字母,并且长度为 `n`。

func X字节集

func X字节集(长度 int) []byte

B 函数获取并返回指定长度 `n` 的随机字节。

func X数字文本

func X数字文本(长度 int) string

Digits 返回一个随机字符串,其中只包含数字,并且其长度为 `n`。

func X整数

func X整数(最大值 int) int

Intn 返回一个在0和max之间的随机整数: [0, max)。

注意事项: 1. 参数`max`必须大于0,否则函数直接返回`max`; 2. 返回结果大于等于0且小于`max`; 3. 返回的随机数是32位整数,并且小于math.MaxUint32。

func X整数数组

func X整数数组(长度 int) []int

Perm 函数返回一个整数切片,其中包含了从 [0, n) 范围内随机排列的 n 个整数。 TODO:优化处理大规模切片生成时的性能。

func X文本

func X文本(长度 int, 包含特殊字符 ...bool) string

S 返回一个随机字符串,该字符串包含数字和字母,其长度为 `n`。 可选参数 `symbols` 指定生成的字符串是否可以包含符号,默认情况下为 false(不包含)。

func X时长

func X时长(最小值, 最大值 time.Duration) time.Duration

D 返回一个在min和max之间随机的time.Duration值:[min, max]。

func X特殊字符文本

func X特殊字符文本(长度 int) string

Symbols 返回一个随机字符串,其中只包含符号,并且其长度为 `n`。

Types

This section is empty.

Jump to

Keyboard shortcuts

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