entropy

package
v0.9.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2024 License: Unlicense Imports: 7 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcquireRand added in v0.9.0

func AcquireRand() *rand.Rand

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

func GetOptimizedRand() *rand.Rand

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

func GetSharedRand() *rand.Rand

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

func OneInA(million int) bool

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

func RNG(n int) int

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

func RandStr(size int) string

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

func RandStrWithUpper(size int) string

RandStrWithUpper generates a random alphanumeric string with a max length of size. Alpha charset used is a-Z mixed case.

func RandomStrChoice

func RandomStrChoice(choice []string) string

RandomStrChoice returns a random item from an input slice of strings.

func ReleaseRand added in v0.9.0

func ReleaseRand(r *rand.Rand)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL