krand

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: MIT Imports: 2 Imported by: 3

README

krand

生成随机字符串、整数、浮点数。


使用示例

生成随机字符串

    /*
	R_NUM = 1      // R_NUM 纯数字
	R_UPPER = 2   // R_UPPER 大写字母
	R_LOWER = 4  // R_LOWER 小写字母
	R_All = 7	       // R_All 数字、大小写字母
    */

	// 通过|或组合出不同类型
    kind := krand.R_NUM|krand.R_UPPER    // 大写字母和数字
    // kind := krand.R_All    // 大小写字母和数字

    krand.String(kind, 10)   // 长度为10,大写字母和数字组成的随机字符串

生成随机整数

    krand.Int(200)            // 随机数范围0 ~ 200
    krand.Int(1000, 2000)  // 随机数范围1000 ~ 2000

生成随机浮点数

    krand.Float64(1, 200)            // 1位小数点的浮点数,范围0~200
    krand.Float64(2, 100,1000)            // 2位小数点的浮点数,范围100~1000

Documentation

Index

Constants

View Source
const (
	// R_NUM 纯数字
	R_NUM = 1
	// R_UPPER 大写字母
	R_UPPER = 2
	// R_LOWER 小写字母
	R_LOWER = 4
	// R_All 数字、大小写字母
	R_All = 7
)

nolint

Variables

This section is empty.

Functions

func Bytes

func Bytes(kind int, bytesLen ...int) []byte

Bytes 生成多种类型的任意长度的随机字符串,如果参数bytesLen为空,默认长度为6 example:Bytes(R_ALL), Bytes(R_ALL, 16), Bytes(R_NUM|R_LOWER, 16)

func Float64

func Float64(dpLength int, rangeSize ...int) float64

Float64 生成指定范围大小随机浮点数, 支持4种传参方式:Float64(dpLength),Float64(dpLength, max),Float64(dpLength, min, max),Float64(dpLength, max, min),min<=随机数<=max

func Int

func Int(rangeSize ...int) int

Int 生成指定范围大小随机数,兼容Int(),Int(max),Int(min, max),Int(max, min)4种方式,min<=随机数<=max

func String

func String(kind int, size ...int) string

String 生成多种类型的任意长度的随机字符串,如果参数size为空,默认长度为6 example:String(R_ALL), String(R_ALL, 16), String(R_NUM|R_LOWER, 16)

Types

This section is empty.

Jump to

Keyboard shortcuts

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