Documentation ¶
Index ¶
Examples ¶
Constants ¶
const DefaultBloomSize = 256 * 256 * 256 * 16 // total filter size in bits
Reasonable default value up to a few hundred thousands different strings.
const MaxUnicode = '\U0010ffff'
MaxUnicode is the maximum Unicode character that can be generated.
const VERSION = "0.3.1"
Variables ¶
var ErrVerificationFailed = fmt.Errorf("verification failed")
Functions ¶
This section is empty.
Types ¶
type Chooser ¶
Chooser defines an interface that allows to make choices.
func NewBytesChooser ¶
NewBytesChooser uses buf as a source of information for decision. This makes the exploration of all possible strings perfectily deterministic. Using a chooser to make a decision "consumes" the available information. When all information is "consumed", defaults or first choices will always be the one chosen.
func NewRandChooser ¶
func NewRandChooser() Chooser
NewRandChooser uses random as the source for decision. It is guaranteed that no string has a zero probability, but longer strings have a much lower chance of appearing.
func NewRandChooserSeed ¶
NewRandChooserSeed uses random as the source for decision. It is guaranteed that no string has a zero probability, but longer strings have a much lower chance of appearing. Setting the seed allows for reproductibility in tests.
type Deduper ¶ added in v0.3.0
type Deduper interface { // Unique is true if string is seen for the first time. Unique(st string) bool }
Deduper is an object that can be used to deduplicate strings.
func NewDedupBloom ¶ added in v0.3.0
Creates a bloom-filter based Deduper. Memory footprint is fixed, driven by bloomsize setting in bits. True result are always right, but after a while, False result are only most likely right. The larger the bloomsize, the less false positive.
func NewDedupMap ¶ added in v0.3.0
func NewDedupMap() Deduper
Creates a map-based Deduper. Memory footprint will grow indefinitely, but response is always exact.
type Gen ¶
type Gen struct {
// contains filtered or unexported fields
}
Gen can generate deterministic or random strings that match a given regexp. Gen is thread safe.
func Must ¶ added in v0.2.0
Must is a utilty to panic on error, when creating a Gen. Typicla use is : g := Must(NewGen(pattern))
func NewGen ¶
NewGen creates a new generator. It returns an error if the regexp provided is not syntaxicaly correct. Use POSIX syntax. No implicit parse tree simplification.
Example ¶
pattern := "a(b|c)a?" generator, err := NewGen(pattern) if err != nil { fmt.Println(err) } entropy := NewRandChooserSeed(42) // or use NewRandInter() for real randomness ... // Generate 5 strings that match "a(b|c)a?" for i := 0; i < 5; i++ { result := generator.Next(entropy) fmt.Println(result) // Verify each generated string actually matches ? if err = generator.Verify(result); err != nil { fmt.Println("Verification failed with error : ", err) } }
Output: aca ab aca ac aba
func NewGenSimpl ¶
Same as NewGen, but in addition, the tree is simplified.