Documentation ¶
Index ¶
- func AcquireRand() *rand.Rand
- func GetCryptoSeed() int64
- func GetOptimizedRand() *rand.Rand
- func GetSharedRand() *rand.Rand
- func OneInA(million int) bool
- func RNG(n int) int
- func RNGUint32() uint32
- func RandSleepMS(n int)
- func RandStr(size int) string
- func RandStrWithUpper(size int) string
- func RandomStrChoice(choice []string) string
- func ReleaseRand(r *rand.Rand)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCryptoSeed ¶ added in v0.3.4
func GetCryptoSeed() int64
GetCryptoSeed returns a random int64 derived from crypto/rand. This can be used as a seed for various PRNGs.
func GetOptimizedRand ¶ added in v0.3.4
GetOptimizedRand returns a pointer to a *new* rand.Rand which uses GetCryptoSeed to seed an rng.SplitMix64. Does not use the global/shared instance of a splitmix64 rng, but instead creates a new one.
func GetSharedRand ¶ added in v0.7.6
GetSharedRand returns a pointer to our shared optimized rand.Rand which uses crypto/rand to seed a splitmix64 rng. WARNING - RACY - This is not thread safe, and should only be used in a single-threaded context.
func OneInA ¶
OneInA generates a random number with a maximum of 'million' (input int). If the resulting random number is equal to 1, then the result is true.
func RNG ¶
RNG returns integer with a maximum amount of 'n' using a global/shared instance of a splitmix64 rng.
- Benchmark_FastRandStr5-24 25205089 47.03 ns/op
- Benchmark_FastRandStr25-24 7113620 169.8 ns/op
- Benchmark_FastRandStr55-24 3520297 340.7 ns/op
- Benchmark_FastRandStr500-24 414966 2837 ns/op
- Benchmark_FastRandStr55555-24 3717 315229 ns/op
func RNGUint32 ¶ added in v0.3.5
func RNGUint32() uint32
RNGUint32 returns a random uint32 using crypto/rand and splitmix64.
func RandSleepMS ¶
func RandSleepMS(n int)
RandSleepMS sleeps for a random period of time with a maximum of n milliseconds.
func RandStr ¶
RandStr generates a random alphanumeric string with a max length of size. Alpha charset used is a-z all lowercase.
func RandStrWithUpper ¶ added in v0.7.0
RandStrWithUpper generates a random alphanumeric string with a max length of size. Alpha charset used is a-Z mixed case.
func RandomStrChoice ¶
RandomStrChoice returns a random item from an input slice of strings.
Types ¶
This section is empty.