26 lines
317 B
Go
26 lines
317 B
Go
package test
|
|
|
|
import (
|
|
"math/rand"
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
func GoProducer(mx *sync.Mutex, ch chan int) {
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
// 生成 [0,100) 随机整数
|
|
randomInt := rand.Intn(100)
|
|
timech := time.Tick(time.Second)
|
|
defer mx.Unlock()
|
|
|
|
for {
|
|
select {
|
|
case <-timech:
|
|
ch <- randomInt
|
|
}
|
|
|
|
}
|
|
|
|
}
|