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\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-10-15 15:26:39 * @FilePath: \go-toolbox\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 FRandBytes(n int) []byte
- 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 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 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 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 ¶ added in v0.0.9
FRandAlphaBytes generates random alpha bytes.
func FRandAlphaString ¶ added in v0.0.9
FRandAlphaString 指定长度的随机字母字符串
func FRandBytes ¶ added in v0.0.9
FRandBytes random bytes, but faster.
func FRandBytesLetters ¶ added in v0.0.9
FRandBytesLetters 生成指定长度的字符切片
func FRandHexBytes ¶ added in v0.0.9
FRandHexBytes generates random hexadecimal bytes.
func FRandHexString ¶ added in v0.0.9
FRandHexString 指定长度的随机 hex 字符串
func FRandString ¶ added in v0.0.9
FRandString a random string, which may contain uppercase letters, lowercase letters and numbers. Ref: stackoverflow.icza
func FRandUint32 ¶ added in v0.0.9
FRandUint32 (>=)min - (<)max
func FastIntn ¶ added in v0.0.9
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 ¶ added in v0.0.9
func FastRand64() uint64
func FastRandn ¶ added in v0.0.9
FastRandn 等同于 FastRandn() % n, 但更快 See https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
func RandString ¶
RandString *
- @Description: 随机生成字符串
- @param n 字符串长度
- @param mode 字符串模式 random.NUMBER|random.LOWERCASE|random.SPECIAL|random.CAPITAL)
- @return str 生成的字符串
func RandomNumber ¶ added in v0.0.9
RandomNumber 随机一个数字字符串
Types ¶
type RandOptions ¶ added in v0.0.9
type RandOptions struct { }
RandOptions
func NewRandOptions ¶ added in v0.0.9
func NewRandOptions() RandOptions
NewRandOptions 创建带有默认值的 RandOptions