randomKit

package
v3.0.94 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// RandFloat 生成随机float64数字,可以指定范围和精度.
	/*
		@param precision 精度(小数点后保留几位)
		@return [min, max)
	*/
	RandFloat func(min, max float64, precision int) float64 = random.RandFloat

	// RandFloatSlice 生成随机float64数字切片,指定长度,范围和精度.
	/*
		PS:
		(1) 切片内的元素范围: [min, max);
		(2) 切片内的元素不会重复.

		@param precision 精度(小数点后保留几位)
	*/
	RandFloatSlice func(n int, min, max float64, precision int) []float64 = random.RandFloats
)
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
)
View Source
var (
	// Int 生成随机int
	/*
		PS:
		(1) 如果min == max,将返回 min;
		(2) 如果min > max,将交换两者的值.

		@param min 可以 < 0
		@param max 可以 < 0
		@return 范围: [min, max)
	*/
	Int func(min, max int) int = random.RandInt
)

Functions

func Bool

func Bool() bool

Types

This section is empty.

Jump to

Keyboard shortcuts

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