Documentation ¶
Index ¶
- Constants
- func FastInt63() int64
- func FastUint32() uint32
- func NewLockedPseudoRand() (*rand.Rand, int64)
- func NewLockedSource(seed int64) rand.Source
- func NewLockedTestRand() (*rand.Rand, int64)
- func NewPseudoRand() (*rand.Rand, int64)
- func NewPseudoSeed() int64
- func NewTestRand() (*rand.Rand, int64)
- func NewTestRandWithSeed(seed int64) *rand.Rand
- func RandBytes(r *rand.Rand, size int) []byte
- func RandDuration(r *rand.Rand, max time.Duration) time.Duration
- func RandInt63InRange(r *rand.Rand, min, max int64) int64
- func RandIntInRange(r *rand.Rand, min, max int) int
- func RandString(rng *rand.Rand, length int, alphabet string) string
- func RandUint64n(r *rand.Rand, n uint64) uint64
- func ReadTestdataBytes(r *rand.Rand, arr []byte)
- func SeedForTests()
Constants ¶
const PrintableKeyAlphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
PrintableKeyAlphabet to use with random string generation to produce strings that doesn't need to be escaped when found as a part of a key and is generally human printable.
Variables ¶
This section is empty.
Functions ¶
func FastInt63 ¶
func FastInt63() int64
FastInt63 returns a non-negative pseudo-random 63-bit integer as an int64. Compared to rand.Int63(), this implementation scales.
func FastUint32 ¶
func FastUint32() uint32
FastUint32 returns a lock free uint32 value. Compared to rand.Uint32, this implementation scales. We're using the go runtime's implementation through a linker trick.
func NewLockedPseudoRand ¶
Same as NewPseudoRand, but the returned Rand is using thread safe underlying source.
func NewLockedSource ¶
NewLockedSource creates random source protected by mutex.
func NewLockedTestRand ¶
NewLockedTestRand is identical to NewTestRand but returned rand.Rand is using thread safe underlying source.
func NewPseudoRand ¶
NewPseudoRand returns an instance of math/rand.Rand seeded from the environment variable COCKROACH_RANDOM_SEED. If that variable is not set, crypto/rand is used to generate a seed. The seed is also returned so we can easily and cheaply generate unique streams of numbers. The created object is not safe for concurrent access.
func NewTestRand ¶
NewTestRand returns an instance of math/rand.Rand seeded from rng, which is seeded with the global seed. If the caller is a test with a different path-qualified name than the previous caller, rng is reseeded from the global seed. This rand.Rand is useful in testing to produce deterministic, reproducible behavior.
func NewTestRandWithSeed ¶
NewTestRandWithSeed returns an instance of math/rand.Rand, similar to NewTestRand, but with the seed specified.
func RandDuration ¶
RandDuration returns a random duration in [0, max).
func RandInt63InRange ¶
RandInt63InRange returns a value in [min, max)
func RandIntInRange ¶
RandIntInRange returns a value in [min, max)
func RandString ¶
RandString generates a random string of the desired length from the input alphabet. It is useful when you want to generate keys that would be printable without further escaping if alphabet is restricted to alphanumeric chars.
func RandUint64n ¶
RandUint64n generates a 64-bit random number in [0, n) range. Note: n == 0 means n is math.MaxUint64 + 1
func ReadTestdataBytes ¶
ReadTestdataBytes reads random bytes, but then nudges them into printable ASCII, *reducing their randomness* to make them a little friendlier for humans using them as testdata.
func SeedForTests ¶
func SeedForTests()
SeedForTests seeds the random number generator and prints the seed value used. This function should be called from TestMain; individual tests should not touch the seed of the global random number generator.
Types ¶
This section is empty.