Documentation
¶
Index ¶
- Constants
- Variables
- func FormatCamelCaseAdjNoun(adjective, noun string, digit int) string
- func FormatHyphenedAdjNoun(adjective, noun string, digit int) string
- func FormatPascalCaseAdjNoun(adjective, noun string, digit int) string
- func Generate() string
- func GenerateCamelCase() string
- func GenerateHyphened() string
- func GeneratePascalCase() string
- func GenerateWithPrefix(prefix string, characters uint8) string
- type AdjNoun
- func NewAdjNoun() *AdjNoundeprecated
- type AdjNounFormat
- type FileDictionaryBuilderdeprecated
- type Prefixed
Examples ¶
Constants ¶
const PrefixedDefaultLen = uint8(6)
PrefixedDefaultLen is the number of characters appended to a prefix when the length is zero.
Variables ¶
var ArabicNumerals = []rune{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}
ArabicNumerals contains the numeric digits 0-9.
var LowercaseAlphabet = []rune{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}
LowercaseAlphabet contains each letter of the alphaber, in lowercase.
var PrefixedDefaultAcceptable = append(append(append([]rune{}, ArabicNumerals...), UppercaseAlphabet...), LowercaseAlphabet...)
PrefixedDefaultAcceptable contains the characters that will be tacked onto the end of the Prefix, if none were provided.
var SpecialCharacters = []rune{'^', '$', '#', '*', '(', ')', '%', '@'}
SpecialCharacters holds a host of standard special characters.
var UppercaseAlphabet = []rune{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}
UppercaseAlphabet contains each letter of the alphabet, in uppercase.
Functions ¶
func FormatCamelCaseAdjNoun ¶ added in v0.2.0
FormatCamelCaseAdjNoun formats an adjective, noun, and number like bigCloud09. Nonnegative numbers are zero-padded to at least two decimal digits.
func FormatHyphenedAdjNoun ¶ added in v0.2.0
FormatHyphenedAdjNoun formats an adjective, noun, and number like big-cloud-09. Nonnegative numbers are zero-padded to at least two decimal digits.
func FormatPascalCaseAdjNoun ¶ added in v0.2.0
FormatPascalCaseAdjNoun formats an adjective, noun, and number like BigCloud09. Nonnegative numbers are zero-padded to at least two decimal digits.
func Generate ¶
func Generate() string
Generate returns a random name using the embedded dictionaries and PascalCase formatting, like BigCloud09. The number ranges from 00 to 99, inclusive.
Example ¶
package main
import (
"fmt"
"github.com/marstr/randname"
)
func main() {
fmt.Println(randname.Generate())
}
Output:
func GenerateCamelCase ¶ added in v0.2.0
func GenerateCamelCase() string
GenerateCamelCase returns a random name using the embedded dictionaries, formatted like bigCloud09, with a number from 00 to 99, inclusive.
Example ¶
package main
import (
"fmt"
"github.com/marstr/randname"
)
func main() {
fmt.Println(randname.GenerateCamelCase())
}
Output:
func GenerateHyphened ¶ added in v0.2.0
func GenerateHyphened() string
GenerateHyphened returns a random name using the embedded dictionaries, formatted like big-cloud-09, with a number from 00 to 99, inclusive.
Example ¶
package main
import (
"fmt"
"github.com/marstr/randname"
)
func main() {
fmt.Println(randname.GenerateHyphened())
}
Output:
func GeneratePascalCase ¶ added in v0.2.0
func GeneratePascalCase() string
GeneratePascalCase returns a random name using the embedded dictionaries, formatted like BigCloud09, with a number from 00 to 99, inclusive.
Example ¶
package main
import (
"fmt"
"github.com/marstr/randname"
)
func main() {
fmt.Println(randname.GeneratePascalCase())
}
Output:
func GenerateWithPrefix ¶
GenerateWithPrefix generates a string with a given prefix then a given number of randomly selected characters. If characters is zero, PrefixedDefaultLen (six) characters are appended.
Example ¶
package main
import (
"fmt"
"github.com/marstr/randname"
)
func main() {
for i := 0; i < 10; i++ {
fmt.Println(randname.GenerateWithPrefix("randname-", 10))
}
}
Output:
Types ¶
type AdjNoun ¶
type AdjNoun struct {
// Adjectives supplies the adjective dictionary. Nil uses the embedded defaults;
// a non-nil empty dictionary omits the adjective.
Adjectives *collection.Dictionary
// Format controls Generate's output. Nil uses FormatPascalCaseAdjNoun.
Format AdjNounFormat
// Nouns supplies the noun dictionary. Nil uses the embedded defaults;
// a non-nil empty dictionary omits the noun.
Nouns *collection.Dictionary
// RandGenerator supplies randomness. Nil uses crypto/rand.Reader.
RandGenerator io.Reader
}
AdjNoun generates a random adjective, noun, and number from 0 to 99, inclusive. Its zero value is ready to use and generates PascalCase names like BigCloud09.
func NewAdjNoun
deprecated
func NewAdjNoun() *AdjNoun
NewAdjNoun returns a generator using PascalCase formatting and crypto/rand.Reader. Its dictionary fields are nil, so generation uses the embedded defaults.
Deprecated: Use the zero value instead, such as var generator AdjNoun.
func (AdjNoun) Generate ¶
Generate returns a random name using the generator's dictionaries, randomness, and Format. A nil Format uses PascalCase, like BigCloud09. The number passed to Format ranges from 0 to 99, inclusive.
Example ¶
package main
import (
"fmt"
"github.com/marstr/randname"
)
func main() {
var generator randname.AdjNoun
fmt.Println(generator.Generate())
}
Output:
func (AdjNoun) GenerateCamelCase ¶ added in v0.2.0
GenerateCamelCase returns a random name using the generator's dictionaries and randomness, formatted like bigCloud09, with a number from 00 to 99, inclusive. It ignores Format without changing it.
Example ¶
package main
import (
"fmt"
"github.com/marstr/randname"
)
func main() {
var generator randname.AdjNoun
fmt.Println(generator.GenerateCamelCase())
}
Output:
func (AdjNoun) GenerateHyphened ¶ added in v0.2.0
GenerateHyphened returns a random name using the generator's dictionaries and randomness, formatted like big-cloud-09, with a number from 00 to 99, inclusive. It ignores Format without changing it.
Example ¶
package main
import (
"fmt"
"github.com/marstr/randname"
)
func main() {
var generator randname.AdjNoun
fmt.Println(generator.GenerateHyphened())
}
Output:
func (AdjNoun) GeneratePascalCase ¶ added in v0.2.0
GeneratePascalCase returns a random name using the generator's dictionaries and randomness, formatted like BigCloud09, with a number from 00 to 99, inclusive. It ignores Format without changing it.
Example ¶
package main
import (
"fmt"
"github.com/marstr/randname"
)
func main() {
var generator randname.AdjNoun
fmt.Println(generator.GeneratePascalCase())
}
Output:
type AdjNounFormat ¶
AdjNounFormat combines an adjective, noun, and number into a formatted name. AdjNoun passes a number from 0 to 99, inclusive.
type FileDictionaryBuilder
deprecated
type FileDictionaryBuilder struct {
Target string
}
FileDictionaryBuilder read words from a file.
Deprecated: Populate a collection.Dictionary directly instead.
func (FileDictionaryBuilder) Build ¶
func (fdb FileDictionaryBuilder) Build(dict *collection.Dictionary) (err error)
Build walks a simple newline delimited file of words and populates a dictionary with them.
type Prefixed ¶
type Prefixed struct {
Prefix string
Acceptable []rune
// Len is the number of random characters to append. Zero uses PrefixedDefaultLen (six), not zero characters.
Len uint8
RandGenerator io.Reader
}
Prefixed offers a means of generating a random name by providing a prefix, followed by a number of random letters or numbers.
Example ¶
package main
import (
"fmt"
"github.com/marstr/randname"
)
func main() {
generator := randname.Prefixed{
Prefix: "randname-",
Acceptable: randname.ArabicNumerals,
Len: 10,
}
for i := 0; i < 10; i++ {
fmt.Println(generator.Generate())
}
}
Output:
func (Prefixed) Generate ¶
Generate creates a string starting with a prefix, and ending with an assortment of randomly chosen runes.
Example ¶
package main
import (
"fmt"
"github.com/marstr/randname"
)
func main() {
generator := randname.Prefixed{
Prefix: "randnameRocks",
}
fmt.Println(generator.Generate())
}
Output: