prand

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

随机数生成工具, 更多随机数生成方法,可对照标准库“math/rand”

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes

func Bytes(n int) []byte

Bytes 方法用于返回指定长度的二进制[]byte数据

func Digits

func Digits(n int) string

Digits 方法用于返回指定长度的随机数字字符串

func Duration

func Duration(min, max time.Duration) time.Duration

Duration 返回一个随机 time.Duration 类型值,即: [min, max].

func Int

func Int(min, max int) int

Int方法返回min到max之间的随机整数,支持负数,包含边界,即:[min, max]

func Intn

func Intn(max int) int

Intn 方法返回大于等0且不大于max的随机整数,即:[0, max]

Note that: 1. The `max` can only be greater than 0, or else it returns `max` directly; 2. The result is greater than or equal to 0, but less than `max`; 3. The result number is 32bit and less than math.MaxUint32.

func Letters

func Letters(n int) string

Letters 方法用于返回指定长度的随机英文字符串.

func Meet

func Meet(num, total int) bool

Meet 用于指定一个数num和总数total,往往 num<=total,并随机计算是否满足num/total的概率。 例如,Meet(1, 100)将会随机计算是否满足百分之一的概率。

func MeetProb

func MeetProb(prob float32) bool

MeetProb 用于给定一个概率浮点数prob,往往 prob<=1.0,并随机计算是否满足该概率。 例如,MeetProb(0.005)将会随机计算是否满足千分之五的概率。

func Perm

func Perm(n int) []int

Perm 产生一个整数切片,范围[0,n]

func StrRand

func StrRand(s string, n int) string

StrRand 方法是一个比较高级的方法,用于从给定的字符列表中选择指定长度的随机字符串返回, 并且支持unicode字符,例如中文。例如,Str("中文123abc", 3)将可能会返回1a文的随机字符串。

func String

func String(n int, symbols ...bool) string

方法用于返回指定长度的数字、字符,第二个参数symbols用于指定是否返回的随机字符串中包含特殊字符,默认false

func Symbols

func Symbols(n int) string

Symbols 方法用于返回指定长度的随机特殊字符串.

Types

This section is empty.

Jump to

Keyboard shortcuts

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