# Random Package random implements some basic functions to generate random int and string.
## Source: [https://github.com/duke-git/lancet/blob/v1/random/random.go](https://github.com/duke-git/lancet/blob/v1/random/random.go)
## Usage: ```go import ( "github.com/duke-git/lancet/random" ) ```
## Index - [RandBytes](#RandBytes) - [RandInt](#RandInt) - [RandString](#RandString) - [RandUpper](#RandUpper) - [RandLower](#RandLower) - [RandNumeral](#RandNumeral) - [RandNumeralOrLetter](#RandNumeralOrLetter) - [UUIdV4](#UUIdV4) - [RandFloat](#RandFloat) - [RandFloats](#RandFloats) - [RandUniqueIntSlice](#RandUniqueIntSlice) - [RandIntSlice](#RandIntSlice) - [RandStringSlice](#RandStringSlice) - [RandBool](#RandBool) - [RandBoolSlice](#RandBoolSlice)
## Documentation ### RandBytes

Generate random byte slice.

Signature: ```go func RandBytes(length int) []byte ``` Example: ```go package main import ( "fmt" "github.com/duke-git/lancet/random" ) func main() { randBytes := random.RandBytes(4) fmt.Println(randBytes) } ``` ### RandInt

Generate random int between min and max, may contain min, not max.

Signature: ```go func RandInt(min, max int) int ``` Example: ```go package main import ( "fmt" "github.com/duke-git/lancet/random" ) func main() { rInt := random.RandInt(1, 10) fmt.Println(rInt) } ``` ### RandString

Generate random given length string. only contains letter (a-zA-Z)

Signature: ```go func RandString(length int) string ``` Example: ```go package main import ( "fmt" "github.com/duke-git/lancet/random" ) func main() { randStr := random.RandString(6) fmt.Println(randStr) //pGWsze } ``` ### RandUpper

Generate a random upper case string

Signature: ```go func RandUpper(length int) string ``` Example: ```go package main import ( "fmt" "github.com/duke-git/lancet/random" ) func main() { randStr := random.RandString(6) fmt.Println(randStr) //PACWGF } ``` ### RandLower

Generate a random lower case string

Signature: ```go func RandLower(length int) string ``` Example: ```go package main import ( "fmt" "github.com/duke-git/lancet/random" ) func main() { randStr := random.RandLower(6) fmt.Println(randStr) //siqbew } ``` ### RandNumeral

Generate a random numeral string

Signature: ```go func RandNumeral(length int) string ``` Example: ```go package main import ( "fmt" "github.com/duke-git/lancet/random" ) func main() { randStr := random.RandNumeral(6) fmt.Println(randStr) //035172 } ``` ### RandNumeralOrLetter

generate a random numeral or letter string

Signature: ```go func RandNumeralOrLetter(length int) string ``` Example: ```go package main import ( "fmt" "github.com/duke-git/lancet/random" ) func main() { randStr := random.RandNumeralOrLetter(6) fmt.Println(randStr) //0aW7cQ } ``` ### UUIdV4

Generate a random UUID of version 4 according to RFC 4122.

Signature: ```go func UUIdV4() (string, error) ``` Example: ```go package main import ( "fmt" "github.com/duke-git/lancet/random" ) func main() { uuid, err := random.UUIdV4() if err != nil { return } fmt.Println(uuid) } ``` ### RandFloat

Generate a random float64 number between [min, max) with specific precision.

Signature: ```go func RandFloat(min, max float64, precision int) float64 ``` Example:[Run](https://go.dev/play/p/zbD_tuobJtr) ```go package main import ( "fmt" "github.com/duke-git/lancet/random" ) func main() { floatNumber := random.RandFloat(1.0, 5.0, 2) fmt.Println(floatNumber) //2.14 (random number) } ``` ### RandFloats

Generate a slice of random float64 numbers of length n that do not repeat. Number range in [min, max)

Signature: ```go func RandFloats(length int, min, max float64, precision int) []float64 ``` Example:[Run](https://go.dev/play/p/I3yndUQ-rhh) ```go package main import ( "fmt" "github.com/duke-git/lancet/random" ) func main() { floatNumbers := random.RandFloats(5, 1.0, 5.0, 2) fmt.Println(floatNumbers) //[3.42 3.99 1.3 2.38 4.23] (random) } ``` ### RandUniqueIntSlice

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

Signature: ```go func RandUniqueIntSlice(n, min, max int) []int ``` Example: ```go package main import ( "fmt" "github.com/duke-git/lancet/random" ) func main() { result := RandUniqueIntSlice(5, 0, 10) fmt.Println(result) //[0 4 7 1 5] (random) } ``` ### RandIntSlice

Generate a slice of random int. Number range in [min, max)

Signature: ```go func RandIntSlice(length, min, max int) []int ``` Example: ```go package main import ( "fmt" "github.com/duke-git/lancet/random" ) func main() { result := random.RandIntSlice(5, 0, 10) fmt.Println(result) //[1 4 7 1 5] (random) } ``` ### RandStringSlice

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.

Signature: ```go func RandStringSlice(charset string, sliceLen, strLen int) []string ``` Example: ```go package main import ( "fmt" "github.com/duke-git/lancet/random" ) func main() { strs := random.RandStringSlice(random.Letters, 4, 6) fmt.Println(strs) // output random string slice like below: //[CooSMq RUFjDz FAeMPf heRyGv] } ``` ### RandBool

Generate a random boolean value (true or false).

Signature: ```go func RandBool() bool ``` Example: ```go package main import ( "fmt" "github.com/duke-git/lancet/random" ) func main() { result := random.RandBool() fmt.Println(result) // true or false (random) } ``` ### RandBoolSlice

Generates a random boolean slice of specified length.

Signature: ```go func RandBoolSlice(length int) []bool ``` Example: ```go package main import ( "fmt" "github.com/duke-git/lancet/random" ) func main() { result := random.RandBoolSlice(2) fmt.Println(result) // [true false] (random) } ```