xrand

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type XRand

type XRand struct {
	*rand.Rand
}

func NewRand

func NewRand(seed int64) *XRand

NewRand 新建种子随机数 XRand。 `seed` 随机种子值。

func (*XRand) Hit

func (r *XRand) Hit(num, total int, randTimes ...int) bool

Hit 用于指定一个数 `num` 和总数 `total` ,往往 num<=total,并随机计算是否满足 num/total 的概率。 `randTimes` 取多少次随机值?(一般取3~5次) 例如,Hit(1, 100)将会随机计算是否满足百分之一的概率。

func (*XRand) HitProb

func (r *XRand) HitProb(prob float32, randTimes ...int) bool

HitProb 用于给定一个概率浮点数 `prob`,往往 prob<=1.0,并随机计算是否满足该概率。 `randTimes` 取多少次随机值?(一般取3~5次) 例如,HitProb(0.005)将会随机计算是否满足千分之五的概率。

func (*XRand) RangeInt

func (r *XRand) RangeInt(min, max int) int

RangeInt 随机整数方法返回 `min` 到 `max` 之间的随机整数,支持负数,包含边界,即:[min, max]。

Jump to

Keyboard shortcuts

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