Documentation ¶
Index ¶
- Variables
- func ByteArray(size int) []byte
- 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
- func TimeDuration(min time.Duration, max time.Duration) time.Duration
- type Coin
- type DiscreteDistributionCandidate
- type DiscreteDistributionCandidateBuildFunc
- type IDiscreteDistributionCandidate
- type IDiscreteDistributionDice
Constants ¶
This section is empty.
Variables ¶
var ErrCandidateIsEmpty = errors.New("candidate is empty")
var ErrInvalidRate = errors.New("invalid rate, must > 0 and <= 1")
var ErrNotHit = errors.New("not hit")
var ErrRawRatesIsEmpty = errors.New("raw randomRates is empty")
var ErrTotalWeightsIsZero = errors.New("total weights is 0")
var ErrWeightsIsEmpty = errors.New("weights is empty")
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 Coin ¶
type Coin struct {
// contains filtered or unexported fields
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 硬币,即只有2面的骰子
type DiscreteDistributionCandidate ¶
type DiscreteDistributionCandidate struct {
// contains filtered or unexported fields
}
DiscreteDistributionCandidate 按概率分布随机骰子候选项代理类
func NewDiscreteDistributionCandidate ¶
func NewDiscreteDistributionCandidate( context interface{}, buildFunc DiscreteDistributionCandidateBuildFunc) *DiscreteDistributionCandidate
NewDiscreteDistributionCandidate 构造权重随机骰子候选项
func (DiscreteDistributionCandidate) Context ¶
func (c DiscreteDistributionCandidate) Context() interface{}
Context 返回按概率分布随机骰子候选项的上下文
func (DiscreteDistributionCandidate) Key ¶
func (c DiscreteDistributionCandidate) Key() interface{}
Key 返回候选项的键值
func (DiscreteDistributionCandidate) Weight ¶
func (c DiscreteDistributionCandidate) Weight() int
Weight 返回候选项的权重
type DiscreteDistributionCandidateBuildFunc ¶
type DiscreteDistributionCandidateBuildFunc = func(context interface{}) (int, interface{})
type IDiscreteDistributionCandidate ¶
type IDiscreteDistributionCandidate interface { Context() interface{} Weight() int Key() interface{} }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// IDiscreteDistributionCandidate 按概率分布随机骰子候选项接口
type IDiscreteDistributionDice ¶
type IDiscreteDistributionDice interface { Append(c IDiscreteDistributionCandidate) IDiscreteDistributionDice Build() (err error) Roll() (ctx interface{}, err error) }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
func NewDiscreteDistributionDice ¶
func NewDiscreteDistributionDice() IDiscreteDistributionDice
NewDiscreteDistributionDice 构造一个按概率分布随机骰子
func NewNormalDiscreteDistributionIntDice ¶
func NewNormalDiscreteDistributionIntDice() IDiscreteDistributionDice
NewNormalDiscreteDistributionIntDice 构造一个键值是int的正态权重随机骰子