rerand

package module
v0.0.0-...-54ad02b Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2023 License: MIT Imports: 8 Imported by: 0

README

go-rerand

GoDoc Build Status

NAME

rerand - Generate random strings based on regular expressions.

DESCRIPTION

rerand makes it trivial to generate random strings. You can use the same regular expression as regexp/syntax.

SYNOPSIS

Programable Interface
import (
    "fmt"
    "log"
    "regexp/syntax"

    "github.com/shogo82148/go-rerand"
)

func main() {
    g, err := rerand.New(`\d{2,3}-\d{3,4}-\d{3,4}`, syntax.Perl, nil)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(g.Generate())
    // 403-165-405

    fmt.Println(g.Generate())
    // 093-0033-3349
}
Command Line Interface
Usage of rerand:
  -d	distinct runes
  -distinct-runes
    	distinct runes
  -h	show help message
  -help
    	show help message
  -n int
    	the number of random strings (default 1)
  -number int
    	the number of random strings (default 1)
  -p float
    	the probability for AltInst
  -prob float
    	the probability for AltInst

INSTALLATION

go get github.com/shogo82148/go-rerand/cmd/rerand

AUTHOR

Ichinose Shogoshogo82148@gmail.com

LICENSE

MIT license. See LICENSE.md for more detail.

SEE ALSO

Documentation

Index

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

func Must(g *Generator, err error) *Generator

Must is a helper that wraps a call to a function returning (*Generator, error) and panics if the error is non-nil.

func New

func New(pattern string, flags syntax.Flags, r *rand.Rand) (*Generator, error)

New returns new Generator.

func NewDistinctRunes

func NewDistinctRunes(pattern string, flags syntax.Flags, r *rand.Rand) (*Generator, error)

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

func (g *Generator) Generate() string

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

func (*Generator) String

func (g *Generator) String() string

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.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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