rand

package
v0.0.0-...-b7aacc1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: Apache-2.0 Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlphaNumericStrBetween

func AlphaNumericStrBetween[T constraints.Integer](minLength T, maxLength T) string

AlphaNumericStrBetween returns a random alphanumeric string of random length in the given limits (inclusive)

func AlphaStrBetween

func AlphaStrBetween[T constraints.Integer](minLength T, maxLength T) string

AlphaStrBetween returns a random alphabetical string of random length in the given limits (inclusive)

func Bytes

func Bytes[T constraints.Integer](len T) []byte

Bytes returns a random slice of bytes of the specified length

func BytesBetween

func BytesBetween[T constraints.Integer](lower T, upper T) []byte

BytesBetween returns a random byte slice of random length in the given limits (upper exclusive)

func HexStr

func HexStr[T constraints.Integer](len T) string

HexStr returns a random hex string of given length

func I64Between

func I64Between[T constraints.Integer](lower T, upper T) int64

I64Between returns a random integer between lower (inclusive) and upper (exclusive). It panics if upper <= lower.

func PosI64

func PosI64() int64

PosI64 returns a positive pseudo-random integer

func Sample

func Sample[T1 any, T2 constraints.Integer](source []T1, count T2, withRedraw ...bool) []T1

Sample returns a new slice with a uniform sample of elements from the source slice. If withRedraw is true, the same element can be chosen multiple times.

func Str

func Str[T constraints.Integer](len T) string

Str returns a random string of given length

func StrBetween

func StrBetween[T constraints.Integer](minLength T, maxLength T) string

StrBetween returns a random string of random length in the given limits (inclusive)

func Time

func Time() time.Time

Time generates a random time

Types

type BoolGen

type BoolGen struct {
	// contains filtered or unexported fields
}

BoolGen represents an random bool generator. Call Stop when done so dangling goroutines can be cleaned up.

func Bools

func Bools(ratio float64) BoolGen

Bools returns a random bool generator that adheres to the given ratio of true to false values.

func (BoolGen) Next

func (g BoolGen) Next() bool

Next returns a single random bool.

func (BoolGen) Take

func (g BoolGen) Take(count int) []bool

Take returns a slice of random bools of the given length.

type DistinctStrGen

type DistinctStrGen struct {
	StringGen
	// contains filtered or unexported fields
}

DistinctStrGen represents an random string generator which returns distinct strings. Call Stop when done so dangling goroutines can be cleaned up.

func (DistinctStrGen) Next

func (g DistinctStrGen) Next() string

Next returns a single random string that is distinct from all previously generated strings.

func (DistinctStrGen) Take

func (g DistinctStrGen) Take(count int) []string

Take returns a slice of distinct random strings of the given length.

type DistrGen

type DistrGen struct {
	// contains filtered or unexported fields
}

DistrGen represents a probability distribution that can be sampled

func Distr

func Distr[T constraints.Integer](n T) DistrGen

Distr generates a new probability distribution with n states of random probability

func (DistrGen) Draw

func (g DistrGen) Draw() int

Draw returns a single sample drawn from the given distribution

func (DistrGen) Samples

func (g DistrGen) Samples(n int) []int

Samples returns n samples drawn from the given distribution

type I64Gen

type I64Gen struct {
	// contains filtered or unexported fields
}

I64Gen represents an random integer generator to generate a sequence of integers with the same properties. Call Stop when done so dangling goroutines can be cleaned up.

func I64GenBetween

func I64GenBetween[T constraints.Integer](lower T, upper T) I64Gen

I64GenBetween returns a random integer generator for numbers between lower (inclusive) and upper (exclusive). It panics if upper <= lower.

func PInt64Gen

func PInt64Gen() I64Gen

PInt64Gen returns a random integer generator for positive integers.

func (I64Gen) Next

func (g I64Gen) Next() int64

Next returns a single random integer.

func (I64Gen) Take

func (g I64Gen) Take(count int) []int64

Take returns a slice of random integers of the given length.

func (I64Gen) Where

func (g I64Gen) Where(predicate func(i int64) bool) I64Gen

Where restricts the output of the underlying generator to adhere to the predicate. If the predicate is not satisfiable the Take function will deadlock.

type StringGen

type StringGen struct {
	// contains filtered or unexported fields
}

StringGen represents an random string generator. Call Stop when done so dangling goroutines can be cleaned up.

func AlphaNumericStrings

func AlphaNumericStrings[T constraints.Integer](minLength T, maxLength T) StringGen

AlphaNumericStrings returns a random string generator that produces strings from the alphanumeric characters of random length in the given limits (inclusive)

func AlphaStrings

func AlphaStrings[T constraints.Integer](minLength T, maxLength T) StringGen

AlphaStrings returns a random string generator that produces strings from the alphabetical characters of random length in the given limits (inclusive)

func HexStrings

func HexStrings[T constraints.Integer](length T) StringGen

HexStrings returns a random hex string generator that produces hex strings with given length

func Strings

func Strings[T constraints.Integer](minLength T, maxLength T) StringGen

Strings returns a random string generator that produces strings from the default alphabet of random length in the given limits (inclusive)

func (StringGen) Distinct

func (g StringGen) Distinct() DistinctStrGen

Distinct returns a new unique string

func (StringGen) Next

func (g StringGen) Next() string

Next returns a single random string.

func (StringGen) Take

func (g StringGen) Take(count int) []string

Take returns a slice of random strings of the given length.

func (StringGen) WithAlphabet

func (g StringGen) WithAlphabet(alphabet []rune) StringGen

WithAlphabet returns a random string generator that produces strings from the given alphabet of length between the given limits (inclusive)

Jump to

Keyboard shortcuts

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