func (g *Generator) SleepOneOf(sleeps ...time.Duration) time.Duration {
	sleep := g.OneDurationOf(sleeps...)
	time.Sleep(sleep)
	return sleep
}
SleepOneOf chooses randomely one of the passed durations
and lets the goroutine sleep for this time.
package audit
import (
	"math/rand"
	"strings"
	"time"
	"unicode"
	"unicode/utf8"
)
var patterns = map[rune]string{
	'0': "0123456789",
	'1': "123456789",
	'o': "01234567",
	'O': "01234567",
	'h': "0123456789abcdef",
	'H': "0123456789ABCDEF",
	'a': "abcdefghijklmnopqrstuvwxyz",
	'A': "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
	'c': "bcdfghjklmnpqrstvwxyz",
	'C': "BCDFGHJKLMNPQRSTVWXYZ",
	'v': "aeiou",
	'V': "AEIOU",
	'z': "abcdefghijklmnopqrstuvwxyz0123456789",
	'Z': "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
}
func SimpleRand() *rand.Rand {
	seed := time.Now().UnixNano()
	source := rand.NewSource(seed)
	return rand.New(source)
}
func FixedRand() *rand.Rand {
	source := rand.NewSource(42)
	return rand.New(source)
}
func ToUpperFirst(s string) string {
	if s == "" {
		return ""
	}
	r, n := utf8.DecodeRuneInString(s)
	return string(unicode.ToUpper(r)) + s[n:]
}
func BuildEMail(first, last, domain string) string {
	valid := make(map[rune]bool)
	for _, r := range "abcdefghijklmnopqrstuvwxyz0123456789-" {
		valid[r] = true
	}
	name := func(in string) string {
		out := []rune{}
		for _, r := range strings.ToLower(in) {
			if valid[r] {
				out = append(out, r)
			}
		}
		return string(out)
	}
	return name(first) + "." + name(last) + "@" + domain
}
func BuildTime(layout string, offset time.Duration) (string, time.Time) {
	t := time.Now().Add(offset)
	ts := t.Format(layout)
	tp, err := time.Parse(layout, ts)
	if err != nil {
		panic("cannot build time: " + err.Error())
	}
	return ts, tp
}
type Generator struct {
	rand *rand.Rand
}
func NewGenerator(rand *rand.Rand) *Generator {
	return &Generator{rand}
}
func (g *Generator) Int(lo, hi int) int {
	if lo == hi {
		return lo
	}
	if lo > hi {
		lo, hi = hi, lo
	}
	n := g.rand.Intn(hi - lo + 1)
	return lo + n
}
func (g *Generator) Ints(lo, hi, count int) []int {
	ints := make([]int, count)
	for i := 0; i < count; i++ {
		ints[i] = g.Int(lo, hi)
	}
	return ints
}
func (g *Generator) Percent() int {
	return g.Int(0, 100)
}
func (g *Generator) FlipCoin(percent int) bool {
	switch {
	case percent > 100:
		percent = 100
	case percent < 0:
		percent = 0
	}
	return g.Percent() >= percent
}
func (g *Generator) OneByteOf(values ...byte) byte {
	i := g.Int(0, len(values)-1)
	return values[i]
}
func (g *Generator) OneRuneOf(values string) rune {
	runes := []rune(values)
	i := g.Int(0, len(runes)-1)
	return runes[i]
}
func (g *Generator) OneIntOf(values ...int) int {
	i := g.Int(0, len(values)-1)
	return values[i]
}
func (g *Generator) OneStringOf(values ...string) string {
	i := g.Int(0, len(values)-1)
	return values[i]
}
func (g *Generator) OneDurationOf(values ...time.Duration) time.Duration {
	i := g.Int(0, len(values)-1)
	return values[i]
}
func (g *Generator) Word() string {
	return g.OneStringOf(words...)
}
func (g *Generator) Words(count int) []string {
	words := make([]string, count)
	for i := 0; i < count; i++ {
		words[i] = g.Word()
	}
	return words
}
func (g *Generator) LimitedWord(lo, hi int) string {
	length := g.Int(lo, hi)
	if length < MinWordLen {
		length = MinWordLen
	}
	if length > MaxWordLen {
		length = MaxWordLen
	}
	pos := g.Int(0, wordsLen)
	for {
		if pos >= wordsLen {
			pos = 0
		}
		if len(words[pos]) == length {
			return words[pos]
		}
		pos++
	}
}
func (g *Generator) Pattern(pattern string) string {
	result := []rune{}
	escaped := false
	for _, pr := range pattern {
		if !escaped {
			if pr == '^' {
				escaped = true
			} else {
				result = append(result, pr)
			}
			continue
		}
		ar := pr
		runes, ok := patterns[pr]
		if ok {
			ar = g.OneRuneOf(runes)
		}
		result = append(result, ar)
		escaped = false
	}
	return string(result)
}
func (g *Generator) Sentence() string {
	count := g.Int(2, 15)
	words := g.Words(count)
	words[0] = ToUpperFirst(words[0])
	for i := 2; i < count-1; i++ {
		if g.FlipCoin(80) {
			words[i] += ","
		}
	}
	return strings.Join(words, " ") + "."
}
func (g *Generator) Paragraph() string {
	count := g.Int(2, 10)
	sentences := make([]string, count)
	for i := 0; i < count; i++ {
		sentences[i] = g.Sentence()
	}
	return strings.Join(sentences, " ")
}
func (g *Generator) Name() (first, middle, last string) {
	if g.FlipCoin(50) {
		return g.FemaleName()
	}
	return g.MaleName()
}
func (g *Generator) MaleName() (first, middle, last string) {
	first = g.OneStringOf(maleFirstNames...)
	middle = g.OneStringOf(maleFirstNames...)
	if g.FlipCoin(80) {
		first += "-" + g.OneStringOf(maleFirstNames...)
	} else if g.FlipCoin(80) {
		middle += "-" + g.OneStringOf(maleFirstNames...)
	}
	last = g.OneStringOf(lastNames...)
	return
}
func (g *Generator) FemaleName() (first, middle, last string) {
	first = g.OneStringOf(femaleFirstNames...)
	middle = g.OneStringOf(femaleFirstNames...)
	if g.FlipCoin(80) {
		first += "-" + g.OneStringOf(femaleFirstNames...)
	} else if g.FlipCoin(80) {
		middle += "-" + g.OneStringOf(femaleFirstNames...)
	}
	last = g.OneStringOf(lastNames...)
	return
}
func (g *Generator) Domain() string {
	tld := g.OneStringOf(topLevelDomains...)
	if g.FlipCoin(80) {
		return g.LimitedWord(3, 5) + "-" + g.LimitedWord(3, 5) + "." + tld
	}
	return g.LimitedWord(3, 10) + "." + tld
}
func (g *Generator) URL() string {
	part := func() string {
		return g.LimitedWord(2, 8)
	}
	start := g.OneStringOf("http://www.", "http://blog.", "https://www.", "ftp://")
	ext := g.OneStringOf("html", "php", "jpg", "mp3", "txt")
	variant := g.Percent()
	switch {
	case variant < 20:
		return start + part() + "." + g.Domain() + "/" + part() + "." + ext
	case variant > 80:
		return start + part() + "." + g.Domain() + "/" + part() + "/" + part() + "." + ext
	default:
		return start + part() + "." + g.Domain()
	}
}
func (g *Generator) EMail() string {
	if g.FlipCoin(50) {
		first, _, last := g.MaleName()
		return BuildEMail(first, last, g.Domain())
	}
	first, _, last := g.FemaleName()
	return BuildEMail(first, last, g.Domain())
}
func (g *Generator) Duration(lo, hi time.Duration) time.Duration {
	if lo == hi {
		return lo
	}
	if lo > hi {
		lo, hi = hi, lo
	}
	n := g.rand.Int63n(int64(hi) - int64(lo) + 1)
	return lo + time.Duration(n)
}