generators

package
v0.0.0-...-e30cafb Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2014 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

The generators package contains a generator with a number of functions for the generation of words, sentences, paragraphs, male and female names, domains, URLs and e-mails and more. They generator creation takes a Rand as parameter. SimpleRand() produces one based on the current time and FixedRand() always the same. That way the generation of test data in larger scenarios can be repeated.

Index

Constants

View Source
const (
	// MinWordLen is the length of the shortest word.
	MinWordLen = 1

	// MaxWordLen is the length of the longest word.
	MaxWordLen = 14
)

Variables

This section is empty.

Functions

func BuildEMail

func BuildEMail(first, last, domain string) string

BuildEMail creates an e-mail address out of first and last name and the domain.

func FixedRand

func FixedRand() *rand.Rand

FixedRand returns a random number generator with a fixed source so that tests using the generate functions can be repeated with the same result.

func SimpleRand

func SimpleRand() *rand.Rand

SimpleRand returns a random number generator with a source using the the current time as seed. It's not the best random, but ok to generate test data.

func ToUpperFirst

func ToUpperFirst(s string) string

ToUpperFirst returns the passed string with the first rune converted to uppercase.

Types

type Generator

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

Generator is responsible for generating different random data based on a random number generator.

func New

func New(rand *rand.Rand) *Generator

New returns a new generator using the passed random number generator.

func (*Generator) Domain

func (g *Generator) Domain() string

Domain generates domain out of name and top level domain.

func (*Generator) Duration

func (g *Generator) Duration(lo, hi time.Duration) time.Duration

Duration generates a duration between lo and hi including those values.

func (*Generator) EMail

func (g *Generator) EMail() string

EMail returns a random e-mail address.

func (*Generator) FemaleName

func (g *Generator) FemaleName() (first, middle, last string)

FemaleName generates a female name consisting out of first, middle and last name.

func (*Generator) FlipCoin

func (g *Generator) FlipCoin(percent int) bool

FlipCoin returns true if the internal generated percentage is equal or greater than the passed percentage.

func (*Generator) Int

func (g *Generator) Int(lo, hi int) int

Int generates an int between lo and hi including those values.

func (*Generator) Ints

func (g *Generator) Ints(lo, hi, count int) []int

Ints generates a slice of random ints.

func (*Generator) LimitedWord

func (g *Generator) LimitedWord(lo, hi int) string

LimitedWord generates a random word with a length between lo and hi.

func (*Generator) MaleName

func (g *Generator) MaleName() (first, middle, last string)

MaleName generates a male name consisting out of first, middle and last name.

func (*Generator) OneByteOf

func (g *Generator) OneByteOf(values ...byte) byte

OneByteOf returns one of the passed bytes.

func (*Generator) OneIntOf

func (g *Generator) OneIntOf(values ...int) int

OneIntOf returns one of the passed ints.

func (*Generator) OneRuneOf

func (g *Generator) OneRuneOf(values string) rune

OneRuneOf returns one of the runes of the passed string.

func (*Generator) OneStringOf

func (g *Generator) OneStringOf(values ...string) string

OneIStringOf returns one of the passed strings.

func (*Generator) Paragraph

func (g *Generator) Paragraph() string

Paragraph generates a paragraph between 2 and 10 sentences.

func (*Generator) Pattern

func (g *Generator) Pattern(pattern string) string

Pattern generates a string based on a pattern. Here different escape chars are replaced by according random chars while all others are left as they are. Escape chars start with a caret (^) followed by specializer. Those are:

- ^ for a caret - 0 for a number between 0 and 9 - 1 for a number between 1 and 9 - o for an octal number - h for a hexadecimal number (lower-case) - H for a hexadecimal number (upper-case) - a for any char between a and z - A for any char between A and Z - c for a consonant (lower-case) - C for a consonant (upper-case) - v for a vowel (lower-case) - V for a vowel (upper-case)

func (*Generator) Percent

func (g *Generator) Percent() int

Percent generates an int between 0 and 100.

func (*Generator) Sentence

func (g *Generator) Sentence() string

Sentence generates a sentence between 2 and 15 words and possibly containing commas.

func (*Generator) Time

func (g *Generator) Time(loc *time.Location, base time.Time, dur time.Duration) time.Time

Time generates a time between the given one and that time plus the given duration. The result will have the passed location.

func (*Generator) URL

func (g *Generator) URL() string

URL generates a http, https or ftp URL, some of the leading to a file.

func (*Generator) Word

func (g *Generator) Word() string

Word generates a random word.

func (*Generator) Words

func (g *Generator) Words(count int) []string

Words generates a slice of random words

Jump to

Keyboard shortcuts

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