kmgRand

package
v0.0.0-...-05317bf Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2015 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FastRandReader io.Reader = &fastRandReader{}

这个东西的首要目标就是快,内容看上去很随机而已 有 200M/s 左右

Functions

func HappendBaseOnPossibility

func HappendBaseOnPossibility(possibility float64) bool

func IntBetween

func IntBetween(min int, max int) int

return a random int in [min,max]

func MustCryptoRandBytes

func MustCryptoRandBytes(length int) []byte

func MustCryptoRandFromByteList

func MustCryptoRandFromByteList(length int, list string) string

func MustCryptoRandToAlphaNum

func MustCryptoRandToAlphaNum(length int) string

func MustCryptoRandToHex

func MustCryptoRandToHex(length int) string

读出给定长度的加密的已经Hex过的字符串(结果字符串就是那么长)

func MustCryptoRandToNum

func MustCryptoRandToNum(length int) string

func MustCryptoRandToReadableAlphaNum

func MustCryptoRandToReadableAlphaNum(length int) string

func NewCryptSeedMathRand

func NewCryptSeedMathRand() (r *mrand.Rand, err error)

func NewLimitedFastRandReader

func NewLimitedFastRandReader(size int) io.Reader

这个东西的首要目标就是快,内容看上去很随机而已 现在速度有 200M/s 左右

func PermStringSlice

func PermStringSlice(slice []string) (output []string)

将字符串数组里面的东西打乱顺序返回

Types

type CombinatoricsRandom2d

type CombinatoricsRandom2d struct {
	ANumList     []int                //key as AKindId物品种类Id,value as 该物品种类出现的数目
	BNumList     []int                //key as BKindId物品种类Id,value as 该物品种类出现的数目
	ValidCombine [][]bool             //key1 as AKindId,key2 as BKindId,value as 该种组合是否可以出现
	Output       []kmgMath.IntVector2 //key2==X as AKindId,key2==Y as BKindId ,value as (AKindId or BKindId)物品种类Id
}

二维排列组合随机问题 A 组物品有若干个种类 ANumList 物品种类AKind 每个种类有ANumList[AKind]个 总数 TotalA=sum(ANumList) B 组物品有若干个种类 BNumList 物品种类BKind 每个种类有BNumList[BKind]个 总数 TotalB=sum(BNumList) 有若干i(物品种类)和j(物品种类)的组合,有一些可以出现,有一些不允许出现 ValidCombine ValidCombine[i][j]==true表示 i(物品种类)和j(物品种类)的组合是可以出现的 ValidCombine[i][j]==false表示 i(物品种类)和j(物品种类)的组合是不可以出现的 要求随机出min(TotalA,TotalB)个 (A,B)的组合,物品不能重复出现,要求出现顺序随机,组合随机

实现: 1.差额补全,给物品总数过小的物品组里面添加一个虚拟物品种类,将数量补全为 TotalA == TotalB,

加入的这个虚拟物品可以和任意其他物品组合.   O(len(ANumList))

2.遍历A的物品种类,(排序数据准备) O(len(ANumList)*len(BNumList))

找到这个A可行的B的物品种类的数量,

3.排序A的物品种类,(排序) O(len(ANumList)*log(len(ANumList)))

下列限制分级排序:可行的B的物品种类的数量少,该A物品种类的物品数量多 排在前面

4.遍历A的物品种类的排序后顺序,(生成) O(sum(BNumList)*sum(BNumlist))

随机生成这个物品种类A的对应的物品种类B,将取走的具体的物品B标记,随后的随机中不取这个物品B
4的详细步骤:
	1.将所有物品B生成一个表,包含每个B的种类,表示还没有被取走的物品B的列表
	2.遍历A的物品,计算出这个物品A可能出现的物品B的列表,
	3.从2的列表中随机取一个,保存到结果中

5.删除所有包含虚拟物品的组合 6.乱序结果列表 O(sum(BNumList))

func (*CombinatoricsRandom2d) Random

func (c *CombinatoricsRandom2d) Random(r *KmgRand) (err error)

type KmgRand

type KmgRand struct {
	*mrand.Rand
}

func MustNewCryptSeedKmgRand

func MustNewCryptSeedKmgRand() (r *KmgRand)

a kmgRand new from crypt source,only use 8 Byte crypt random...

func NewCryptSeedKmgRand

func NewCryptSeedKmgRand() (r *KmgRand, err error)

a kmgRand new from crypt source,only use 8 Byte crypt random...

func NewInt64SeedKmgRand

func NewInt64SeedKmgRand(seed int64) (r *KmgRand)

func (*KmgRand) ChoiceFromIntSlice

func (r *KmgRand) ChoiceFromIntSlice(slice []int) int

func (*KmgRand) Float64Between

func (r *KmgRand) Float64Between(min float64, max float64) float64

func (*KmgRand) HappendBaseOnPossibility

func (r *KmgRand) HappendBaseOnPossibility(possibility float64) bool

return true if that event happend in that possibility. possibility should be float in [0,1]

func (*KmgRand) Int63Between

func (r *KmgRand) Int63Between(min int64, max int64) int64

func (*KmgRand) IntBetween

func (r *KmgRand) IntBetween(min int, max int) int

return a random int in [min,max]

func (*KmgRand) MulitChoice

func (r *KmgRand) MulitChoice(totalLength int, choiceNumber int) []int

return not repeat size number in [0,n) as random order, it will panic if size>n or size<0 or n<0

func (*KmgRand) MulitChoiceOriginOrder

func (r *KmgRand) MulitChoiceOriginOrder(n int, size int) []int

return not repeat size number in [0,n) as origin order, it will panic if size>n or size<0 or n<0

func (*KmgRand) PermIntSlice

func (r *KmgRand) PermIntSlice(slice []int) (output []int)

func (*KmgRand) TimeDurationBetween

func (r *KmgRand) TimeDurationBetween(min time.Duration, max time.Duration) time.Duration

type LcgTransformer

type LcgTransformer struct {
	Start uint64 //start of target range(included)
	Range uint64 //length of target range
	A     uint64 //lcg parameter a
	C     uint64 //lcg parameter c
}

func (LcgTransformer) Generate

func (t LcgTransformer) Generate(i uint64) (output uint64)

func (LcgTransformer) GenerateInRange

func (t LcgTransformer) GenerateInRange(i uint64) (output uint64)

在范围内进行变换,如果超出规定的范围会报错 map a num from [0,t.Range-1] to [Start,Start+Range-1] .

type PossibilityWeightRander

type PossibilityWeightRander struct {
	SearchList []float64
	Total      float64
}

please use NewPossibilityWeightRander, field expose only for serialize

func NewPossibilityWeightRander

func NewPossibilityWeightRander(weightList []float64) PossibilityWeightRander

func (PossibilityWeightRander) ChoiceOne

func (p PossibilityWeightRander) ChoiceOne(r *KmgRand) (Index int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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