random

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandFloatNomarlsize added in v0.1.1

func RandFloatNomarlsize() float32

RandFloatNomarlsize 随机生成 (-1.0, 1.0) 的浮点数

func RandNumber added in v0.1.1

func RandNumber(min int, max int) int

RandNumber 随机一个指定访问的int [min,max)

func RandStringHex

func RandStringHex(n int) (string, error)

Generate a random string for hexadecimal. Docker Id use this.

func RandStringNumber

func RandStringNumber(n int) (string, error)

RandStringNumber 创建指定位数的数字字符串; n < 18 , 常用于短信验证码等情况

Types

type Choice

type Choice struct {
	Item   interface{} // Item 元素
	Weight uint        // 权重值
}

Choice 选择项的结构

type WeightRand

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

WeightRand 加权随机

func NewWeightRand

func NewWeightRand(data []Choice) WeightRand

NewWeightRand 创建一个加权随机算法。 该算法使用将权重放入一个有序数组,然后从随机数,二分法去查找有效区间,得出结果

func (WeightRand) Pick

func (wr WeightRand) Pick() interface{}

Pick 选出随机数,此处利用二分查找的特点

Jump to

Keyboard shortcuts

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