Documentation ¶
Overview ¶
* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-08-05 09:16:55 * @FilePath: \go-toolbox\pkg\random\model.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-11-11 10:28:33 * @FilePath: \go-toolbox\pkg\random\rand.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
Index ¶
- Constants
- func FRandAlphaBytes(n int) []byte
- func FRandAlphaString(n int) string
- func FRandBool() bool
- func FRandBytes(n int) []byte
- func FRandBytesJSON(length int) (string, error)
- func FRandBytesLetters(n int, letters string) []byte
- func FRandDecBytes(n int) []byte
- func FRandDecString(n int) string
- func FRandHexBytes(n int) []byte
- func FRandHexString(n int) string
- func FRandInt(min, max int) int
- func FRandString(n int) string
- func FRandTime() time.Time
- func FRandUint32(min, max uint32) uint32
- func FastIntn(n int) int
- func FastRand() uint32
- func FastRand64() uint64
- func FastRandn(n uint32) uint32
- func FastRandu() uint
- func GenerateRandomModel(model interface{}) (interface{}, string, error)
- func NewRand(seed ...int64) *rand.Rand
- func RandFloat(min, max float64) (v float64)
- func RandInt(min, max int) (v int)
- func RandString(n int, mode RandType) (str string)
- func RandStringSlice(count, len int, mode RandType) (result []string)
- func RandomHex(bytesLen int, customBytes ...string) string
- func RandomNumber(length int, customBytes ...string) string
- func RandomStr(length int, customBytes ...string) string
- type RandOptions
- type RandType
Constants ¶
const ( // 自定义数字区间 DEC_BYTES = "0123456789" // 自定义hex区间 HEX_BYTES = "ABCDEF0123456789" // 自定义字符区间 ALPHA_BYTES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" LETTER_BYTES = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" LETTER_IDX_BITS = 6 // 6 bits to represent a letter index LETTER_IDX_MASK = 1<<LETTER_IDX_BITS - 1 // All 1-bits, as many as letterIdxBits LETTER_IDX_MAX = 31 / LETTER_IDX_BITS // # of letter indices fitting in 31 bits )
Variables ¶
This section is empty.
Functions ¶
func FRandAlphaBytes ¶
FRandAlphaBytes generates random alpha bytes.
func FRandBytesJSON ¶
FRandBytesJSON 生成指定长度的随机字节字符串,并返回 JSON 格式
func FRandBytesLetters ¶
FRandBytesLetters 生成指定长度的字符切片
func FRandHexBytes ¶
FRandHexBytes generates random hexadecimal bytes.
func FRandString ¶
FRandString a random string, which may contain uppercase letters, lowercase letters and numbers. Ref: stackoverflow.icza
func FastIntn ¶
FastIntn this is similar to rand.Intn, but faster. A non-negative pseudo-random number in the half-open interval [0,n). Return 0 if n <= 0.
func FastRand64 ¶
func FastRand64() uint64
func FastRandn ¶
FastRandn 等同于 FastRandn() % n, 但更快 See https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
func GenerateRandomModel ¶
GenerateRandomModel 生成随机模型的 JSON 格式
func RandString ¶
RandString *
- @Description: 随机生成字符串
- @param n 字符串长度
- @param mode 字符串模式 random.NUMBER|random.LOWERCASE|random.SPECIAL|random.CAPITAL)
- @return str 生成的字符串
func RandStringSlice ¶ added in v0.11.1
RandStringSlice 指定长度的随机字符串
func RandomNumber ¶
RandomNumber 随机一个数字字符串