mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-04 12:52:28 +08:00
1.6 KiB
1.6 KiB
Random
Package random implements some basic functions to generate random int and string.
Source:
https://github.com/duke-git/lancet/blob/main/random/random.go
Usage:
import (
"github.com/duke-git/lancet/random"
)
Index
Documentation
RandBytes
Generate random byte slice.
Signature:
func RandBytes(length int) []byte
Example:
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:
func RandInt(min, max int) int
Example:
package main
import (
"fmt"
"github.com/duke-git/lancet/random"
)
func main() {
rInt := random.RandInt(1, 10)
fmt.Println(rInt)
}
RandInt
Generate random given length string.
Signature:
func RandString(length int) string
Example:
package main
import (
"fmt"
"github.com/duke-git/lancet/random"
)
func main() {
randStr := random.RandString(6)
fmt.Println(randStr)
}