Documentation ¶
Index ¶
- Variables
- func ByteArray(size int) []byte
- func Duration(min time.Duration, max time.Duration) time.Duration
- func GenRandomRatesInt(weights map[int]int) (rates map[int]float64, err error)
- func Int(min int, max int) int
- func Int32(min int32, max int32) int32
- func Int64(min int64, max int64) int64
- func NormalDiscreteDistributionInt(fixRates map[int]float64, randomRates map[int]float64) (map[int]float64, int, error)
- func NormalDistributionRandom(mu float64, sigma float64) float64
- func String(size int) string
- type Coin
- type DiscreteDistributionCandidate
- type DiscreteDistributionCandidateBuildFunc
- type IDiscreteDistributionCandidate
- type IDiscreteDistributionDice
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrWeightsIsEmpty = errors.New("weights is empty") ErrTotalWeightsIsZero = errors.New("total weights is 0") ErrRawRatesIsEmpty = errors.New("raw randomRates is empty") ErrCandidateIsEmpty = errors.New("candidate is empty") ErrNotHit = errors.New("not hit") ErrInvalidRate = errors.New("invalid rate, must > 0 and <= 1") )
Functions ¶
func GenRandomRatesInt ¶
GenRandomRatesInt 根据整型权重值生成浮点权重值
func NormalDiscreteDistributionInt ¶
func NormalDiscreteDistributionInt(fixRates map[int]float64, randomRates map[int]float64) (map[int]float64, int, error)
NormalDiscreteDistributionInt 键值是int的正态权重随机
Types ¶
type DiscreteDistributionCandidate ¶
type DiscreteDistributionCandidate struct {
// contains filtered or unexported fields
}
DiscreteDistributionCandidate 按概率分布随机骰子候选项代理类
func NewDiscreteDistributionCandidate ¶
func NewDiscreteDistributionCandidate( context any, buildFunc DiscreteDistributionCandidateBuildFunc) *DiscreteDistributionCandidate
NewDiscreteDistributionCandidate 构造权重随机骰子候选项
func (DiscreteDistributionCandidate) Context ¶
func (c DiscreteDistributionCandidate) Context() any
Context 返回按概率分布随机骰子候选项的上下文
func (DiscreteDistributionCandidate) Key ¶
func (c DiscreteDistributionCandidate) Key() any
Key 返回候选项的键值
func (DiscreteDistributionCandidate) Weight ¶
func (c DiscreteDistributionCandidate) Weight() int
Weight 返回候选项的权重
type IDiscreteDistributionCandidate ¶
IDiscreteDistributionCandidate 按概率分布随机骰子候选项接口
type IDiscreteDistributionDice ¶
type IDiscreteDistributionDice interface { Append(c IDiscreteDistributionCandidate) IDiscreteDistributionDice Build() (err error) Roll() (ctx any, err error) }
func NewDiscreteDistributionDice ¶
func NewDiscreteDistributionDice() IDiscreteDistributionDice
NewDiscreteDistributionDice 构造一个按概率分布随机骰子
func NewNormalDiscreteDistributionIntDice ¶
func NewNormalDiscreteDistributionIntDice() IDiscreteDistributionDice
NewNormalDiscreteDistributionIntDice 构造一个键值是int的正态权重随机骰子
Click to show internal directories.
Click to hide internal directories.