Documentation
¶
Index ¶
- Variables
- func Probability(per int32, args ...int32) bool
- func Relative(items map[int32]int32) int32
- func RelativeMulti(items map[int32]int32, num int32, repeat ...bool) []int32
- func Roll(a, b int32) int32
- type Bytes
- type Data
- type Less
- type Random
- func (this *Random) Add(k, v int32)
- func (this *Random) Filter(filter func(k, v int32) bool, less ...Less) *Random
- func (this *Random) Less(i, j *Data) bool
- func (this *Random) Multi(num int) (r []int32)
- func (this *Random) Probability(args ...int32) (r []int32)
- func (this *Random) Range(f func(k, v int32) bool)
- func (this *Random) Reset(filter func(k, v int32) int32, less ...Less) *Random
- func (this *Random) Roll() int32
- func (this *Random) Sort(less ...Less) *Random
- func (this *Random) Weight() (r int32)
Constants ¶
This section is empty.
Variables ¶
View Source
var Strings = NewBytes([]byte("0123456789abcdefghijklmnopqrstuvwxyz"))
Strings 默认的随机字符串生成器,使用 crypto/rand 作为熵源,适合生成 token/secret。 注意:游戏概率类随机请用 Roll / Probability / Relative(math/rand)。
Functions ¶
func Probability ¶
Probability 独立概率,args单位,默认万分比,,,百分比传入100
func RelativeMulti ¶
RelativeMulti 相对概率,权重,返回多个。repeat 是否可以重复。 不修改传入的 items map(内部拷贝后操作)。
Types ¶
type Bytes ¶ added in v1.1.0
type Bytes struct {
// contains filtered or unexported fields
}
Bytes 基于自定义字符集 + crypto/rand 的安全随机字符串生成器。
type Random ¶
type Random struct {
// contains filtered or unexported fields
}
func (*Random) Probability ¶ added in v1.2.0
Probability 按独立概率计算每一组的命中
Click to show internal directories.
Click to hide internal directories.