Last active
March 21, 2017 01:48
-
-
Save spiegel-im-spiegel/53c32b9060b50d5cad57 to your computer and use it in GitHub Desktop.
「ズンドコキヨシ」と擬似乱数 ref: http://qiita.com/spiegel-im-spiegel/items/6a5bc07dbfa46a328e26
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ go run zundoko.go | |
ドコズンドコズンズンドコズンズンドコドコズンドコドコドコズンズンズンズンドコキ・ヨ・シ! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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