random

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Probability

func Probability(per int32, args ...int32) bool

Probability 独立概率,args单位,默认万分比,,,百分比传入100

func Relative

func Relative(items map[int32]int32) int32

Relative 相对概率,权重

func RelativeMulti

func RelativeMulti(items map[int32]int32, num int32, repeat ...bool) []int32

RelativeMulti 相对概率,权重 返回多个,repeat 是否可以重复

func Roll

func Roll(a, b int32) int32

Types

type Data added in v1.0.7

type Data struct {
	Key int32 //序号
	Val int32 //权重
}

func (*Data) GetKey added in v1.0.7

func (this *Data) GetKey() int32

func (*Data) GetVal added in v1.0.7

func (this *Data) GetVal() int32

type Less added in v1.0.7

type Less func(a, b *Data) bool

type Random

type Random struct {
	// contains filtered or unexported fields
}

func New

func New(items map[int32]int32, less ...Less) *Random

func (*Random) Filter added in v1.0.7

func (this *Random) Filter(filter func(k, v int32) bool) *Random

Filter 根据 filter 剔除不符合规则的项目

func (*Random) Multi

func (this *Random) Multi(num int) (r []int32)

Multi 随机多个不重复

func (*Random) Range added in v1.0.6

func (this *Random) Range(f func(k, v int32) bool)

func (*Random) Reset added in v1.0.7

func (this *Random) Reset(filter func(k, v int32) int32) *Random

Reset 根据 filter 重新设定权重

func (*Random) Roll

func (this *Random) Roll() int32

Roll 简单的权重算法,直接计算区间落点

func (*Random) Sort added in v1.0.7

func (this *Random) Sort(f Less)

func (*Random) Weight added in v1.0.6

func (this *Random) Weight() (r int32)

Jump to

Keyboard shortcuts

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