random

package
v0.11.6 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

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

View Source
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

func FRandAlphaBytes(n int) []byte

FRandAlphaBytes generates random alpha bytes.

func FRandAlphaString

func FRandAlphaString(n int) string

FRandAlphaString 指定长度的随机字母字符串

func FRandBool

func FRandBool() bool

生成随机布尔值

func FRandBytes

func FRandBytes(n int) []byte

FRandBytes random bytes, but faster.

func FRandBytesJSON

func FRandBytesJSON(length int) (string, error)

FRandBytesJSON 生成指定长度的随机字节字符串,并返回 JSON 格式

func FRandBytesLetters

func FRandBytesLetters(n int, letters string) []byte

FRandBytesLetters 生成指定长度的字符切片

func FRandDecBytes

func FRandDecBytes(n int) []byte

RandDecBytes 指定长度的随机数字切片

func FRandDecString

func FRandDecString(n int) string

FRandDecString 指定长度的随机数字字符串

func FRandHexBytes

func FRandHexBytes(n int) []byte

FRandHexBytes generates random hexadecimal bytes.

func FRandHexString

func FRandHexString(n int) string

FRandHexString 指定长度的随机 hex 字符串

func FRandInt

func FRandInt(min, max int) int

FRandInt (>=)min - (<)max

func FRandString

func FRandString(n int) string

FRandString a random string, which may contain uppercase letters, lowercase letters and numbers. Ref: stackoverflow.icza

func FRandTime

func FRandTime() time.Time

生成随机时间

func FRandUint32

func FRandUint32(min, max uint32) uint32

FRandUint32 (>=)min - (<)max

func FastIntn

func FastIntn(n int) int

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 FastRand

func FastRand() uint32

FastRand 随机数

func FastRand64

func FastRand64() uint64

func FastRandn

func FastRandn(n uint32) uint32

FastRandn 等同于 FastRandn() % n, 但更快 See https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/

func FastRandu

func FastRandu() uint

func GenerateRandomModel

func GenerateRandomModel(model interface{}) (interface{}, string, error)

GenerateRandomModel 生成随机模型的 JSON 格式

func NewRand

func NewRand(seed ...int64) *rand.Rand

NewRand goroutine-safe rand.Rand, optional seed value

func RandFloat

func RandFloat(min, max float64) (v float64)

RandFloat *

  • @Description: 随机小数
  • @param min
  • @param max
  • @return v

func RandInt

func RandInt(min, max int) (v int)

RandInt *

  • @Description: 随机整数
  • @param start
  • @param end
  • @return v

func RandString

func RandString(n int, mode RandType) (str string)

RandString *

  • @Description: 随机生成字符串
  • @param n 字符串长度
  • @param mode 字符串模式 random.NUMBER|random.LOWERCASE|random.SPECIAL|random.CAPITAL)
  • @return str 生成的字符串

func RandStringSlice added in v0.11.1

func RandStringSlice(count, len int, mode RandType) (result []string)

RandStringSlice 指定长度的随机字符串

func RandomHex

func RandomHex(bytesLen int, customBytes ...string) string

RandomHex 随机一个hex字符串

func RandomNumber

func RandomNumber(length int, customBytes ...string) string

RandomNumber 随机一个数字字符串

func RandomStr

func RandomStr(length int, customBytes ...string) string

RandomStr 随机一个字符串

Types

type RandOptions

type RandOptions struct {
}

RandOptions

func NewRandOptions

func NewRandOptions() RandOptions

NewRandOptions 创建带有默认值的 RandOptions

type RandType

type RandType int
const (
	// CAPITAL 包含大写字母
	CAPITAL RandType = iota + 1 // 自定义扩展
	// LOWERCASE 包含小写字母
	LOWERCASE
	// SPECIAL 包含特殊字符
	SPECIAL
	// NUMBER 包含数字
	NUMBER
)

Jump to

Keyboard shortcuts

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