Documentation
¶
Index ¶
- Variables
- type Generator
- func Must(g *Generator, err error) *Generator
- func New(pattern string, flags syntax.Flags, r *rand.Rand) (*Generator, error)
- func NewDistinctRunes(pattern string, flags syntax.Flags, r *rand.Rand) (*Generator, error)
- func NewWithProbability(pattern string, flags syntax.Flags, r *rand.Rand, prob int64) (*Generator, error)
- type RuneGenerator
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrTooManyRepeat = errors.New("rerand: counted too many repeat")
ErrTooManyRepeat the error used for New.
Functions ¶
This section is empty.
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator is random string generator
func Must ¶
Must is a helper that wraps a call to a function returning (*Generator, error) and panics if the error is non-nil.
func NewDistinctRunes ¶
NewDistinctRunes returns new Generator.
func NewWithProbability ¶
func NewWithProbability(pattern string, flags syntax.Flags, r *rand.Rand, prob int64) (*Generator, error)
NewWithProbability returns new Generator.
func (*Generator) Generate ¶
Generate generates a random string. It is safe for concurrent use by multiple goroutines.
Example ¶
package main import ( "fmt" "math/rand" "regexp/syntax" rerand "github.com/shogo82148/go-rerand" ) func main() { r := rand.New(rand.NewSource(1)) g := rerand.Must(rerand.New(`\d{2,3}-\d{3,4}-\d{3,4}`, syntax.Perl, r)) fmt.Println(g.Generate()) fmt.Println(g.Generate()) }
Output: 17-9180-604 29-4156-568
type RuneGenerator ¶
type RuneGenerator struct {
// contains filtered or unexported fields
}
RuneGenerator is random rune generator.
func NewRuneGenerator ¶
func NewRuneGenerator(runes []rune, r *rand.Rand) *RuneGenerator
NewRuneGenerator returns new RuneGenerator.
func (*RuneGenerator) Generate ¶
func (g *RuneGenerator) Generate() rune
Generate generates random rune. It is safe for concurrent use by multiple goroutines.
Click to show internal directories.
Click to hide internal directories.