package main import fmt math rand func main channels make chan bool fo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"fmt"
"math/rand"
)
func main() {
channels := make([]chan bool, 6)
for i := range channels {
channels[i] = make(chan bool)
}
go func() {
for {
channels[rand.Intn(6)] <- true
}
}()
for i := 0; i < 36; i++ {
var x int
select {
case <-channels[0]:
x = 1
case <-channels[1]:
x = 2
case <-channels[2]:
x = 3
case <-channels[3]:
x = 4
case <-channels[4]:
x = 5
case <-channels[5]:
x = 6
}
fmt.Printf("%d ", x)
}
fmt.Println()
}