random

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: MIT Imports: 8 Imported by: 3

Documentation

Overview

Package random implements some basic functions to generate random int and string.

Index

Constants

View Source
const (
	MaximumCapacity = math.MaxInt>>1 + 1
	Numeral         = "0123456789"
	LowwerLetters   = "abcdefghijklmnopqrstuvwxyz"
	UpperLetters    = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	Letters         = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	SymbolChars     = "!@#$%^&*()_+-=[]{}|;':\",./<>?"
)

Variables

This section is empty.

Functions

func RandBool added in v1.4.4

func RandBool() bool

RandBool generates a random boolean value (true or false).

func RandBoolSlice added in v1.4.4

func RandBoolSlice(length int) []bool

RandBoolSlice generates a random boolean slice of specified length.

func RandBytes

func RandBytes(length int) []byte

RandBytes generate random byte slice. Play: https://go.dev/play/p/EkiLESeXf8d

func RandFloat added in v1.4.3

func RandFloat(min, max float64, precision int) float64

RandFloat generate random float64 number between [min, max) with specific precision.

func RandFloats added in v1.4.3

func RandFloats(n int, min, max float64, precision int) []float64

RandFloats generate a slice of random float64 numbers of length n that do not repeat.

func RandInt

func RandInt(min, max int) int

RandInt generate random int between [min, max).

func RandIntSlice added in v1.4.4

func RandIntSlice(length, min, max int) []int

RandIntSlice generates a slice of random integers. The generated integers are between min and max (exclusive).

func RandLower added in v1.3.3

func RandLower(length int) string

RandLower generate a random lower case string of specified length.

func RandNumeral added in v1.3.3

func RandNumeral(length int) string

RandNumeral generate a random numeral string of specified length.

func RandNumeralOrLetter added in v1.3.3

func RandNumeralOrLetter(length int) string

RandNumeralOrLetter generate a random numeral or alpha string of specified length.

func RandString

func RandString(length int) string

RandString generate random alpha string of specified length.

func RandStringSlice added in v1.4.4

func RandStringSlice(charset string, sliceLen, strLen int) []string

RandString generate a slice of random string of length strLen based on charset. chartset should be one of the following: random.Numeral, random.LowwerLetters, random.UpperLetters random.Letters, random.SymbolChars, random.AllChars. or a combination of them.

func RandSymbolChar added in v1.4.3

func RandSymbolChar(length int) string

RandSymbolChar generate a random symbol char of specified length. symbol chars: !@#$%^&*()_+-=[]{}|;':\",./<>?.

func RandUniqueIntSlice added in v1.4.0

func RandUniqueIntSlice(n, min, max int) []int

RandUniqueIntSlice generate a slice of random int of length n that do not repeat.

func RandUpper added in v1.3.3

func RandUpper(length int) string

RandUpper generate a random upper case string of specified length.

func UUIdV4 added in v1.2.5

func UUIdV4() (string, error)

UUIdV4 generate a random UUID of version 4 according to RFC 4122.

Types

This section is empty.

Jump to

Keyboard shortcuts

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