grand

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2024 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GRand

type GRand struct {
	*rand.Rand
	// contains filtered or unexported fields
}

func NewRand

func NewRand(seed int64, safe ...bool) *GRand

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

func (*GRand) Hit

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

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

func (*GRand) HitProb

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

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

func (*GRand) RangeInt added in v1.2.7

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

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

func (*GRand) Shuffle added in v1.3.0

func (r *GRand) Shuffle(n int, swap func(i, j int))

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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