You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 3 Current »
grand模块实现了对随机数操作的封装和改进,实现了极高的随机数生成性能,提供了丰富的随机数相关操作方法。
grand
使用方式:
import "github.com/gogf/gf/util/grand"
接口文档:
https://godoc.org/github.com/gogf/gf/util/grand
常用方法:
func N(min, max int) int func B(n int) []byte func S(n int, symbols ...bool) string func Str(s string, n int) string func Intn(max int) int func Digits(n int) string func Letters(n int) string func Meet(num, total int) bool func MeetProb(prob float32) bool func Perm(n int) []int func Symbols(n int) string
字符类型 字符列表 数字字符 0123456789 英文字符 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 特殊字符 !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~
Intn
0
max
[0, max)
N
min
[min, max]
B
[]byte
S
symbols
Str
unicode
Str("中文123abc", 3)
1a文
Digits
Letters
Symbols
Meet
num
total
num<=total
num/total
Meet(1, 100)
MeetProb
prob
prob<=1.0
MeetProb(0.005)