gen

package
v0.0.0-...-96f1409 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func String

func String(length, cardinality int) string

String returns a random string with the given length (<=32), from a set of possible strings of size "cardinality".

func Time

func Time(from time.Time, maxDelta time.Duration) time.Time

Time returns a time increasing from the "from" time with a random delta.

func Uint64

func Uint64(cardinality int) uint64

Uint64 gets a zipfian random uint64 with the given cardinality.

Types

type Generator

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

Generator holds state for generating random data in certain distributions.

func NewGenerator

func NewGenerator(seed int64) *Generator

NewGenerator gets a new Generator

func (*Generator) String

func (g *Generator) String(length, cardinality int) string

String gets a zipfian random string from a set with the given cardinality.

func (*Generator) Time

func (g *Generator) Time(from time.Time, maxDelta time.Duration) time.Time

Time returns a time increasing from the "from" time with a random delta.

func (*Generator) Uint64

func (g *Generator) Uint64(cardinality int) uint64

Uint64 gets a zipfian random uint64 with the given cardinality.

type PermutationGenerator

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

PermutationGenerator provides a way to pass integer IDs through a permutation map that is pseudorandom but repeatable. This could be done with rand.Perm, but that would require storing a [Iterations]int64 array, which we want to avoid for large values of Iterations. It works by using a Linear Congruence Generator (https://en.wikipedia.org/wiki/Linear_congruential_generator) with modulus m = Iterations, c = an arbitrary prime, a = computed to ensure the full period. relevant stackoverflow: http://cs.stackexchange.com/questions/29822/lazily-computing-a-random-permutation-of-the-positive-integers

func NewPermutationGenerator

func NewPermutationGenerator(m int64, seed int64) *PermutationGenerator

NewPermutationGenerator returns a PermutationGenerator which will permute numbers in 0-n.

func (*PermutationGenerator) Permute

func (p *PermutationGenerator) Permute(n int64) int64

Permute gets the permuted value for n.

Jump to

Keyboard shortcuts

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