Skip to content

Latest commit

 

History

History
26 lines (23 loc) · 336 Bytes

go-rand.md

File metadata and controls

26 lines (23 loc) · 336 Bytes

###go生成随机数

package main

import (
	"fmt"
	"math/rand"
	"time"
)

func randGenerator() chan int {
	out := make(chan int)
	go func() {
		for {
			rand.Seed(time.Now().Unix())
			out <- rand.Intn(100)
		}
	}()
	return out
}

func main() {
	randServiceHandler := randGenerator()
	fmt.Printf("%d\n", <-randServiceHandler)
}