randvar

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRand

func NewRand() *rand.Rand

NewRand creates a new random number generator seeded with the current time.

Types

type BytesFlag

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

BytesFlag provides a command line flag interface for specifying random bytes. The specification provides for both the length of the random bytes and a target compression ratio.

func NewBytesFlag

func NewBytesFlag(spec string) *BytesFlag

NewBytesFlag creates a new BytesFlag initialized with the specified spec.

func (*BytesFlag) Bytes

func (f *BytesFlag) Bytes(r *rand.Rand, buf []byte) []byte

Bytes returns random bytes. The length of the random bytes comes from the internal sizeFlag.

func (*BytesFlag) Set

func (f *BytesFlag) Set(spec string) error

Set implements the Flag.Value interface.

func (*BytesFlag) String

func (f *BytesFlag) String() string

func (*BytesFlag) Type

func (f *BytesFlag) Type() string

Type implements the Flag.Value interface.

type Deck

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

Deck is a random number generator that generates numbers in the range [0,len(weights)-1] where the probability of i is weights(i)/sum(weights). Unlike Weighted, the weights are specified as integers and used in a deck-of-cards style random number selection which ensures that each element is returned with a desired frequency within the size of the deck.

func NewDeck

func NewDeck(rng *rand.Rand, weights ...int) *Deck

NewDeck returns a new deck random number generator.

func (*Deck) Int

func (d *Deck) Int() int

Int returns a random number in the range [0,len(weights)-1] where the probability of i is weights(i)/sum(weights).

type Dynamic

type Dynamic interface {
	Static

	// Increment the max value the variable will return.
	IncMax(delta int)

	// Read the current max value the variable will return.
	Max() uint64
}

Dynamic models a random variable that pulls from a distribution with an upper bound that can change dynamically using the IncMax method.

type Flag

type Flag struct {
	Static
	// contains filtered or unexported fields
}

Flag provides a command line flag interface for specifying static random variables.

func NewFlag

func NewFlag(spec string) *Flag

NewFlag creates a new Flag initialized with the specified spec.

func (*Flag) Set

func (f *Flag) Set(spec string) error

Set implements the Flag.Value interface.

func (*Flag) String

func (f *Flag) String() string

func (*Flag) Type

func (f *Flag) Type() string

Type implements the Flag.Value interface.

type SkewedLatest

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

SkewedLatest is a random number generator that generates numbers in the range [min, max], but skews it towards max using a zipfian distribution.

func NewDefaultSkewedLatest

func NewDefaultSkewedLatest() (*SkewedLatest, error)

NewDefaultSkewedLatest constructs a new SkewedLatest generator with the default parameters.

func NewSkewedLatest

func NewSkewedLatest(min, max uint64, theta float64) (*SkewedLatest, error)

NewSkewedLatest constructs a new SkewedLatest generator with the given parameters. It returns an error if the parameters are outside the accepted range.

func (*SkewedLatest) IncMax

func (z *SkewedLatest) IncMax(delta int)

IncMax increments max.

func (*SkewedLatest) Max

func (z *SkewedLatest) Max() uint64

Max returns max.

func (*SkewedLatest) Uint64

func (z *SkewedLatest) Uint64(rng *rand.Rand) uint64

Uint64 returns a random Uint64 between min and max, where keys near max are most likely to be drawn.

type Static

type Static interface {
	Uint64(rng *rand.Rand) uint64
}

Static models a random variable that pulls from a distribution with static bounds

type Uniform

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

Uniform is a random number generator that generates draws from a uniform distribution.

func NewUniform

func NewUniform(min, max uint64) *Uniform

NewUniform constructs a new Uniform generator with the given parameters. Returns an error if the parameters are outside the accepted range.

func (*Uniform) IncMax

func (g *Uniform) IncMax(delta int)

IncMax increments max.

func (*Uniform) Max

func (g *Uniform) Max() uint64

Max returns the max value of the distribution.

func (*Uniform) Uint64

func (g *Uniform) Uint64(rng *rand.Rand) uint64

Uint64 returns a random Uint64 between min and max, drawn from a uniform distribution.

type Weighted

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

Weighted is a random number generator that generates numbers in the range [0,len(weights)-1] where the probability of i is weights(i)/sum(weights).

func NewWeighted

func NewWeighted(rng *rand.Rand, weights ...float64) *Weighted

NewWeighted returns a new weighted random number generator.

func (*Weighted) Int

func (w *Weighted) Int() int

Int returns a random number in the range [0,len(weights)-1] where the probability of i is weights(i)/sum(weights).

type Zipf

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

Zipf is a random number generator that generates random numbers from a Zipf distribution. Unlike rand.Zipf, this generator supports incrementing the max parameter without performing an expensive recomputation of the underlying hidden parameters, which is a pattern used in [1] for efficiently generating large volumes of Zipf-distributed records for synthetic data. Second, rand.Zipf only supports theta <= 1, we suppose all values of theta.

func NewDefaultZipf

func NewDefaultZipf() (*Zipf, error)

NewDefaultZipf constructs a new Zipf generator with the default parameters.

func NewZipf

func NewZipf(min, max uint64, theta float64) (*Zipf, error)

NewZipf constructs a new Zipf generator with the given parameters. Returns an error if the parameters are outside the accepted range.

func (*Zipf) IncMax

func (z *Zipf) IncMax(delta int)

IncMax increments max and recomputes the internal values that depend on it. Returns an error if the recomputation failed.

func (*Zipf) Max

func (z *Zipf) Max() uint64

Max returns the max.

func (*Zipf) Uint64

func (z *Zipf) Uint64(rng *rand.Rand) uint64

Uint64 draws a new value between min and max, with probabilities according to the Zipf distribution.

Jump to

Keyboard shortcuts

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