sample

package
v0.0.0-...-9c21ab8 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandChoice

func RandChoice(array []int, n int) []int

func RandChoiceInt32

func RandChoiceInt32(array []int32, n int) []int32

func RandInt

func RandInt(min, max int) int

闭区间

func RandInt32

func RandInt32(min, max int32) int32

func RandInt64

func RandInt64(min, max int64) int64

func RandomString

func RandomString(l int) string

随机字符串,包含大小写字母和数字

func Shuffle

func Shuffle(array []int)

func ShuffleInt32

func ShuffleInt32(array []int32)

func ShuffleInt64

func ShuffleInt64(array []int64)

func ShuffleUint64

func ShuffleUint64(array []uint64)

func WeightedChoice

func WeightedChoice(weightArray []int) int

根据权重随机,返回对应选项的索引,O(n)

Types

type AliasTable

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

AliasTable is a discrete distribution

func NewAlias

func NewAlias(weightList []int32, src rand.Source) AliasTable

新建一个抽样器,weightList是权重列表,src是随机数种子

func (*AliasTable) Next

func (v *AliasTable) Next() int

Next returns the next random value from the discrete distribution

Jump to

Keyboard shortcuts

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