randomKit

package
v3.0.924 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// LetterString 生成给定长度的随机字符串,只包含字母(a-zA-Z).
	/*
		e.g.
			fmt.Println(randomKit.LetterString(20))	// lheIFnhIxSiBteKONNii
	*/
	LetterString func(length int) string = random.RandString

	// NumberString 生成给定长度的随机数字字符串(0-9).
	NumberString func(length int) string = random.RandNumeral

	// LowerString 生成给定长度的随机小写字母字符串(a-z).
	LowerString func(length int) string = random.RandLower

	// UpperString 生成给定长度的随机大写字母字符串(A-Z).
	UpperString func(length int) string = random.RandUpper

	// NumberOrLetterString 生成给定长度的随机字符串(数字 + 字母; A-Z + a-z + 0-9).
	NumberOrLetterString func(length int) string = random.RandNumeralOrLetter
)
View Source
var Bytes func(n int) []byte = grand.B

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

e.g.

data := randomKit.Bytes(20)
fmt.Println(data) // [193 72 130 210 86 72 180 144 91 246 162 215 176 4 169 153 130 140 89 15]
View Source
var (
	// Duration
	/*
		@return a random time.Duration between min and max: [min, max]
	*/
	Duration func(min, max time.Duration) time.Duration = grand.D
)

Functions

func Bool

func Bool() bool

func Int

func Int(min, max int) int

Int 生成随机int.(参考: random.RandInt)

TODO: 看后续 duke-git/lancet(目前v2.3.1) 会不会加条件编译.

PS:
(1) 如果min == max,将返回 min;
(2) 如果min > max,将交换两者的值.

@param min 可以 < 0
@param max 可以 < 0
@return 范围: [min, max)

func RandFloat

func RandFloat(min, max float64, precision int) float64

RandFloat 生成随机float64数字,可以指定范围和精度.(参考: random.RandFloat)

TODO: 看后续 duke-git/lancet(目前v2.3.1) 会不会加条件编译.

@param precision 	(1) 精度(小数点后保留几位)
					(2) 真正返回值的小数位,可能会 小于 传参precision
@return [min, max)

e.g. 返回值的小数位,可能会 小于 传参precision
	randomKit.RandFloat(1, 2, 3) => 1.938
	randomKit.RandFloat(1, 2, 3) => 1.36
	randomKit.RandFloat(1, 2, 3) => 1.41
	randomKit.RandFloat(1, 2, 3) => 1.184

func RandFloatSlice

func RandFloatSlice(n int, min, max float64, precision int) []float64

RandFloatSlice 生成随机float64数字切片,指定长度,范围和精度.(参考: random.RandFloats)

TODO: 看后续 duke-git/lancet(目前v2.3.1) 会不会加条件编译.

@param precision 精度(小数点后保留几位)
@return (1) 切片内的元素范围: [min, max)
		(2) 切片内的元素不会重复

Types

This section is empty.

Jump to

Keyboard shortcuts

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