Logo

Programming-Idioms

History of Idiom 70 > diff from v15 to v16

Edit summary for version 16 by :
[Go] +DocURL

Version 15

2015-11-30, 12:37:30

Version 16

2015-12-30, 17:04:22

Idiom #70 Use clock as random generator seed

Get the current date and provide it as a seed to a random generator. The generator sequence will be different at each run.

Idiom #70 Use clock as random generator seed

Get the current date and provide it as a seed to a random generator. The generator sequence will be different at each run.

Imports
import (
	"math/rand"
	"time"
)
Imports
import (
	"math/rand"
	"time"
)
Code
rand.Seed(time.Now().UnixNano())
Code
rand.Seed(time.Now().UnixNano())
Comments bubble
This initializes the default Source.
Comments bubble
This initializes the default Source.
Doc URL
https://golang.org/pkg/math/rand/#Seed
Demo URL
http://play.golang.org/p/3sk_hOz0PH
Demo URL
http://play.golang.org/p/3sk_hOz0PH