package rand
import "k8s.io/apimachinery/pkg/util/rand"
Package rand provides utilities related to randomization.
Index ¶
- func Int() int
- func Int63nRange(min, max int64) int64
- func Intn(max int) int
- func IntnRange(min, max int) int
- func Perm(n int) []int
- func SafeEncodeString(s string) string
- func Seed(seed int64)
- func String(n int) string
Functions ¶
func Int ¶
func Int() int
Int returns a non-negative pseudo-random int.
func Int63nRange ¶
IntnRange generates an int64 integer in range [min,max). By design this should panic if input is invalid, <= 0.
func Intn ¶
Intn generates an integer in range [0,max). By design this should panic if input is invalid, <= 0.
func IntnRange ¶
IntnRange generates an integer in range [min,max). By design this should panic if input is invalid, <= 0.
func Perm ¶
Perm returns, as a slice of n ints, a pseudo-random permutation of the integers [0,n) from the default Source.
func SafeEncodeString ¶
SafeEncodeString encodes s using the same characters as rand.String. This reduces the chances of bad words and ensures that strings generated from hash functions appear consistent throughout the API.
func Seed ¶
func Seed(seed int64)
Seed seeds the rng with the provided seed.
func String ¶
String generates a random alphanumeric string, without vowels, which is n characters long. This will panic if n is less than zero. How the random string is created: - we generate random int63's - from each int63, we are extracting multiple random letters by bit-shifting and masking - if some index is out of range of alphanums we neglect it (unlikely to happen multiple times in a row)
Source Files ¶
rand.go
- Version
- v0.19.15-rc.0
- Published
- Jul 12, 2021
- Platform
- js/wasm
- Imports
- 3 packages
- Last checked
- 3 hours ago –
Tools for package owners.