random

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

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

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 added in v0.0.9

func FRandAlphaBytes(n int) []byte

FRandAlphaBytes generates random alpha bytes.

func FRandAlphaString added in v0.0.9

func FRandAlphaString(n int) string

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

func FRandBytes added in v0.0.9

func FRandBytes(n int) []byte

FRandBytes random bytes, but faster.

func FRandBytesLetters added in v0.0.9

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

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

func FRandDecBytes added in v0.0.9

func FRandDecBytes(n int) []byte

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

func FRandDecString added in v0.0.9

func FRandDecString(n int) string

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

func FRandHexBytes added in v0.0.9

func FRandHexBytes(n int) []byte

FRandHexBytes generates random hexadecimal bytes.

func FRandHexString added in v0.0.9

func FRandHexString(n int) string

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

func FRandInt added in v0.0.9

func FRandInt(min, max int) int

FRandInt (>=)min - (<)max

func FRandString added in v0.0.9

func FRandString(n int) string

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

func FRandUint32 added in v0.0.9

func FRandUint32(min, max uint32) uint32

FRandUint32 (>=)min - (<)max

func FastIntn added in v0.0.9

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 added in v0.0.9

func FastRand() uint32

FastRand 随机数

func FastRand64 added in v0.0.9

func FastRand64() uint64

func FastRandn added in v0.0.9

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 added in v0.0.9

func FastRandu() uint

func NewRand added in v0.0.9

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 RandomHex

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

RandomHex 随机一个hex字符串

func RandomNumber added in v0.0.9

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

RandomNumber 随机一个数字字符串

func RandomStr

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

RandomStr 随机一个字符串

Types

type RandOptions added in v0.0.9

type RandOptions struct {
}

RandOptions

func NewRandOptions added in v0.0.9

func NewRandOptions() RandOptions

NewRandOptions 创建带有默认值的 RandOptions

type RandType added in v0.0.9

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