# Random
Package random implements some basic functions to generate random int and string.
# Source:
# Usage:
import ( "github.com/duke-git/lancet/v2/random" )
Copied!
# Documentation
# RandBytes
Generate random byte slice.
Signature:
func RandBytes(length int) []byte
Copied!
Example:
package main import ( "fmt" "github.com/duke-git/lancet/v2/random" ) func main() { randBytes := random.RandBytes(4) fmt.Println(randBytes) }
Copied!
# RandInt
Generate random int between min and max, may contain min, not max.
Signature:
func RandInt(min, max int) int
Copied!
Example:
package main import ( "fmt" "github.com/duke-git/lancet/v2/random" ) func main() { rInt := random.RandInt(1, 10) fmt.Println(rInt) }
Copied!
# RandInt
Generate random given length string.
Signature:
func RandString(length int) string
Copied!
Example:
package main import ( "fmt" "github.com/duke-git/lancet/v2/random" ) func main() { randStr := random.RandString(6) fmt.Println(randStr) }
Copied!
# UUIdV4
Generate a random UUID of version 4 according to RFC 4122.
Signature:
func UUIdV4() (string, error)
Copied!
Example:
package main import ( "fmt" "github.com/duke-git/lancet/v2/random" ) func main() { uuid, err := random.UUIdV4() if err != nil { return } fmt.Println(uuid) }
Copied!