random

package
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LCG_A uint32 = 1664525
	LCG_C uint32 = 1013904223
)

Variables

This section is empty.

Functions

func GetRandomNumber

func GetRandomNumber(args string, n int, randz *rand.Rand) []int

*

  • 数值抽取器(从枚举值,范围随机值,定值 中随机抽出一个值)
  • 枚举值(支持单个出现概率):1,2,4 或 1:10,2:30,4:30
  • 范围值: 1~10
  • 定值:12
  • 支持混合使用 如:1~10,44~89,2~5 又如 2~10:40
  • 支持概率后缀 代表该值被抽取出来的几率 值越高被抽出的概率越大 并不限定后缀值的范围 如:1:20,1~4:30,4:500 *
  • @param args
  • @param n 随机个数
  • @param radom
  • @return

func GetRandomNumbers

func GetRandomNumbers(args string, randz *rand.Rand) []int

*

  • 加权随机数 数值抽取器 *
  • @param args 以“#”劈分数组然后再在数组元素中每一位获取一个随机数
  • @param radom
  • @see #GetRandomNumber(String, Random)
  • @return

func GetRandomValues

func GetRandomValues(numbers []int, n int, radom *rand.Rand) []int

*

  • 从给定的一些数值里随机抽取N个数 *
  • @param numbers,给定的等待抽取的列表
  • @param n 要随机多n个数
  • @return

func GetRandomValuesInt64

func GetRandomValuesInt64(numbers []int64, n int, randz *rand.Rand) []int64

*

  • 从给定的一些数值里随机抽取N个数 *
  • @param numbers,给定的等待抽取的列表
  • @param n 要随机多n个数
  • @return

func GetRandomWeight

func GetRandomWeight(data RandInterface, n int, randz *rand.Rand) interface{}

GetRandomWeight 随机数选取

func RandInt

func RandInt(min int, max int, randz *rand.Rand) int

func RandInt32

func RandInt32(min int32, max int32, randz *rand.Rand) int32

func RandInt64

func RandInt64(min int64, max int64, randz *rand.Rand) int64

Types

type LCGRand

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

func NewLCGRand

func NewLCGRand(seed uint32) *LCGRand

func (*LCGRand) NextRand

func (lcg *LCGRand) NextRand() uint32

func (*LCGRand) RandFloat64

func (lcg *LCGRand) RandFloat64() float64

func (*LCGRand) RandN

func (lcg *LCGRand) RandN(n uint32) uint32

范围[0,n)

type RandInterface

type RandInterface interface {
	Len() int
	Weight(i int) int
	SubValue(indexs []int) interface{}
}

RandInterface 随机数选取器接口

type RandItem

type RandItem struct {
	ItemID  int32 `json:"itemId"`  //奖励物品ID
	Num     int32 `json:"num"`     //数量
	TimeOut int32 `json:"timeout"` //过期时间
	Weight  int32 `json:"weight"`  //权重
}

func GetRandomItems

func GetRandomItems(items []RandItem, n int, randz *rand.Rand) []RandItem

Jump to

Keyboard shortcuts

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