urand

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: May 13, 2023 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Intn

func Intn(max int) int

Intn 返回一个随机的整数,其值区间 [0, max)

func RandInWeights

func RandInWeights(weightList Weights) int

RandInWeights 计算权重,并返回数组下标

func Rate

func Rate() float64

Rate 返回一个随机的百分比概率,其值区间 [0, 1.0)

Types

type BaseWeights

type BaseWeights []int

BaseWeights 将 []int 包装为 Weights 接口

func Wrap

func Wrap(v []int) BaseWeights

Wrap 将 []int 包装为baseWeights

func (BaseWeights) GetWeight

func (b BaseWeights) GetWeight(i int) int

GetWeight 获取指定权重

func (BaseWeights) TotalLen

func (b BaseWeights) TotalLen() int

TotalLen 总长度

func (BaseWeights) TotalWeight

func (b BaseWeights) TotalWeight() int

TotalWeight 总权重

type Weights

type Weights interface {
	TotalLen() int
	TotalWeight() int
	GetWeight(int) int
}

Weights 权重列表

Jump to

Keyboard shortcuts

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