Skip to content

Instantly share code, notes, and snippets.

@spiegel-im-spiegel
Last active March 21, 2017 01:48
Show Gist options
  • Save spiegel-im-spiegel/53c32b9060b50d5cad57 to your computer and use it in GitHub Desktop.
Save spiegel-im-spiegel/53c32b9060b50d5cad57 to your computer and use it in GitHub Desktop.
「ズンドコキヨシ」と擬似乱数 ref: http://qiita.com/spiegel-im-spiegel/items/6a5bc07dbfa46a328e26
$ go run zundoko.go
ドコズンドコズンズンドコズンズンドコドコズンドコドコドコズンズンズンズンドコキ・ヨ・シ!
// A Source represents a source of uniformly-distributed
// pseudo-random int64 values in the range [0, 1<<63).
type Source interface {
Int63() int64
Seed(seed int64)
}
import (
"math/rand"
"time"
"github.com/seehuhn/mt19937"
)
func generate() chan string {
ch := make(chan string)
go func() {
var zundoko = [2]string{zun, doko}
r := rand.New(mt19937.New())
r.Seed(time.Now().UnixNano())
for {
ch <- zundoko[r.Intn(2)]
}
}()
return ch
}
package main
import (
"fmt"
"math/rand"
"time"
)
const (
zun = "ズン"
doko = "ドコ"
kiyoshi = "キ・ヨ・シ!"
)
func generate() chan string {
ch := make(chan string)
go func() {
var zundoko = [2]string{zun, doko}
rand.Seed(time.Now().UnixNano())
for {
ch <- zundoko[rand.Intn(2)]
}
}()
return ch
}
func main() {
zundoko := generate()
zcount := 0
for {
zd := <-zundoko
fmt.Print(zd)
if zd == zun {
zcount++
} else if zcount >= 4 {
break
} else {
zcount = 0
}
}
fmt.Print(kiyoshi)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment