Logo

Programming-Idioms

History of Idiom 70 > diff from v20 to v21

Edit summary for version 21 by :
[Go] Conciser imports

Version 20

2016-02-22, 14:43:52

Version 21

2016-02-22, 15:28:53

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"
import "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
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