├── .travis.yml ├── haikunator_test.go ├── README.md └── haikunator.go /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | script: go test 3 | -------------------------------------------------------------------------------- /haikunator_test.go: -------------------------------------------------------------------------------- 1 | package haikunator 2 | 3 | import ( 4 | "testing" 5 | "time" 6 | ) 7 | 8 | func TestAreGeneratedNamesRandomOrNot(t *testing.T) { 9 | names := make([]string, 50) 10 | 11 | for i, _ := range names { 12 | haikunator := New(time.Now().UTC().UnixNano()) 13 | names[i] = haikunator.Haikunate() 14 | } 15 | 16 | for i, name1 := range names { 17 | for j, name2 := range names { 18 | if i != j && name1 == name2 { 19 | t.Fatalf("not unique: %v : %v and %v :%v", i, j, name1, name2) 20 | } 21 | } 22 | } 23 | } 24 | 25 | func TestTotalCombinations(t *testing.T) { 26 | // This test should be kept up-to-date with the README 27 | expected := 8645 28 | found := len(ADJECTIVES) * len(NOUNS) 29 | if expected != found { 30 | t.Fatalf("mismatched total combinations: expected %v but found %v", expected, found) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | go-haikunator [![Build Status](https://travis-ci.org/yelinaung/go-haikunator.svg?branch=master)](https://travis-ci.org/yelinaung/go-haikunator) 2 | ============= 3 | 4 | Heroku-like memorable random name generator. Golang port of [haikunator](https://github.com/usmanbashir/haikunator). 5 | 6 | By default the generator provides 8645 unique combinations. 7 | 8 | ```bash 9 | sparkling-cherry 10 | snowy-brook 11 | bitter-darkness 12 | ``` 13 | 14 | View the [docs](https://godoc.org/github.com/yelinaung/go-haikunator). 15 | 16 | Example 17 | ------- 18 | ```go 19 | package main 20 | 21 | import ( 22 | "fmt" 23 | "github.com/yelinaung/go-haikunator" 24 | "time" 25 | ) 26 | 27 | func main() { 28 | haikunator := haikunator.New(time.Now().UTC().UnixNano()) 29 | fmt.Println(haikunator.HaikuNate()) 30 | } 31 | 32 | ``` 33 | 34 | Other Languages 35 | ------- 36 | Haikunator is also available in other languages. Check them out: 37 | - Node: https://github.com/AtroxDev/haikunatorjs 38 | - Python: https://github.com/AtroxDev/haikunator 39 | - Ruby: https://github.com/usmanbashir/haikunator 40 | 41 | 42 | License 43 | ------- 44 | MIT 45 | 46 | -------------------------------------------------------------------------------- /haikunator.go: -------------------------------------------------------------------------------- 1 | package haikunator 2 | 3 | import ( 4 | "fmt" 5 | "math/rand" 6 | ) 7 | 8 | var ( 9 | ADJECTIVES = []string{"aged", "ancient", "autumn", "billowing", "bitter", "black", "blue", "bold", 10 | "broad", "broken", "calm", "cold", "cool", "crimson", "curly", "damp", 11 | "dark", "dawn", "delicate", "divine", "dry", "empty", "falling", "fancy", 12 | "flat", "floral", "fragrant", "frosty", "gentle", "green", "hidden", "holy", 13 | "icy", "jolly", "late", "lingering", "little", "lively", "long", "lucky", 14 | "misty", "morning", "muddy", "mute", "nameless", "noisy", "odd", "old", 15 | "orange", "patient", "plain", "polished", "proud", "purple", "quiet", "rapid", 16 | "raspy", "red", "restless", "rough", "round", "royal", "shiny", "shrill", 17 | "shy", "silent", "small", "snowy", "soft", "solitary", "sparkling", "spring", 18 | "square", "steep", "still", "summer", "super", "sweet", "throbbing", "tight", 19 | "tiny", "twilight", "wandering", "weathered", "white", "wild", "winter", "wispy", 20 | "withered", "yellow", "young"} 21 | NOUNS = []string{"art", "band", "bar", "base", "bird", "block", "boat", "bonus", 22 | "bread", "breeze", "brook", "bush", "butterfly", "cake", "cell", "cherry", 23 | "cloud", "credit", "darkness", "dawn", "dew", "disk", "dream", "dust", 24 | "feather", "field", "fire", "firefly", "flower", "fog", "forest", "frog", 25 | "frost", "glade", "glitter", "grass", "hall", "hat", "haze", "heart", 26 | "hill", "king", "lab", "lake", "leaf", "limit", "math", "meadow", 27 | "mode", "moon", "morning", "mountain", "mouse", "mud", "night", "paper", 28 | "pine", "poetry", "pond", "queen", "rain", "recipe", "resonance", "rice", 29 | "river", "salad", "scene", "sea", "shadow", "shape", "silence", "sky", 30 | "smoke", "snow", "snowflake", "sound", "star", "sun", "sunset", 31 | "surf", "term", "thunder", "tooth", "tree", "truth", "union", "unit", 32 | "violet", "voice", "water", "waterfall", "wave", "wildflower", "wind", "wood"} 33 | ) 34 | 35 | type Name interface { 36 | Haikunate() string 37 | Size() int 38 | } 39 | 40 | type RandomName struct { 41 | r *rand.Rand 42 | } 43 | 44 | func (r RandomName) Haikunate() string { 45 | return fmt.Sprintf("%v-%v", ADJECTIVES[r.r.Intn(len(ADJECTIVES))], NOUNS[r.r.Intn(len(NOUNS))]) 46 | } 47 | 48 | func (r RandomName) Size() int { 49 | return len(ADJECTIVES) * len(NOUNS) 50 | } 51 | 52 | func New(seed int64) Name { 53 | name := RandomName{rand.New(rand.New(rand.NewSource(99)))} 54 | name.r.Seed(seed) 55 | return name 56 | } 57 | --------------------------------------------------------------------------------