rand

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2022 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccAddr

func AccAddr() sdk.AccAddress

AccAddr generates a random cosmos address

func Bytes

func Bytes(len int) []byte

Bytes returns a random slice of bytes of the specified length

func BytesBetween

func BytesBetween(minLength int, maxLength int) []byte

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

func Context added in v0.9.0

func Context(store types.MultiStore) sdk.Context

Context generates a random Context data structure

func Denom added in v0.12.0

func Denom(min, max int) string

Denom returns a random denom string

func HexStr

func HexStr(len int) string

HexStr returns a random hex string of given length

func I64Between

func I64Between(lower int64, upper int64) int64

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

func NormalizeString added in v0.12.0

func NormalizeString(str string) string

NormalizeString normalizes a string as NFKC

func NormalizedStr added in v0.12.0

func NormalizedStr(len int) string

NormalizedStr creates a random normalized string of the provided length

func NormalizedStrBetween added in v0.12.0

func NormalizedStrBetween(min, max int) string

NormalizedStrBetween creates a random normalized string in the provided range

func Of added in v0.17.0

func Of[T any](items ...T) T

Of returns a random item from the given slice

func PosI64

func PosI64() int64

PosI64 returns a positive pseudo-random integer

func Str

func Str(len int) string

Str returns a random string of given length

func StrBetween

func StrBetween(minLength int, maxLength int) string

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

func ValAddr

func ValAddr() sdk.ValAddress

ValAddr generates a random validator address

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(n int) 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(lower int64, upper int64) 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 HexStrings

func HexStrings(length int) StringGen

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

func Strings

func Strings(minLength int, maxLength int) 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