Skip to content

Instantly share code, notes, and snippets.

@nmatsui
Created November 11, 2014 05:29
Show Gist options
  • Save nmatsui/40e5d9abd76f86539e2e to your computer and use it in GitHub Desktop.
Save nmatsui/40e5d9abd76f86539e2e to your computer and use it in GitHub Desktop.
bonjovi generator
package main
import (
"fmt"
"math/rand"
"time"
)
type Stream chan string
const BADNAME = "ジョンボンジョヴィ"
var ELEMENTS = []string{"ボ", "ン", "ジョ", "ヴィ"}
func main() {
ns := generateName()
for {
name := <-ns
fmt.Printf("%s, ", name)
if BADNAME == name {
fmt.Printf("You Give Love A Bad Name!\n")
return
}
}
}
func generateName() Stream {
s := make(Stream)
var r string
go func() {
es := randomElement()
for {
r = ""
for i := 0; i < 6; i++ {
r += <-es
}
s <- r
}
}()
return s
}
func randomElement() Stream {
s := make(Stream)
go func() {
rand.Seed(time.Now().Unix())
for {
s <- ELEMENTS[rand.Intn(len(ELEMENTS))]
}
}()
return s
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment