Files
goLearn/test/Producer.go

26 lines
317 B
Go
Raw Normal View History

2025-08-31 13:10:56 +08:00
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
}
}
}