golang随机数及pipe



var pipe1  = make(chan int, 1000)
func piTest(){
	for{
		data := <- pipe1
		fmt.Printf("get data:%v\n", data)
	}

}


func putData(){
	for {
		source := rand.NewSource(time.Now().UnixNano())
		dataR := rand.New(source).Intn(100)
		time.Sleep(time.Second *1 )
		pipe1 <- dataR
	}
}

func main(){
	go piTest()
	go putData()
	time.Sleep(time.Minute* 1)
}



posted @ 2019-10-17 14:34  nanaindi  阅读(174)  评论(0编辑  收藏  举报