Logo

Programming-Idioms

History of Idiom 70 > diff from v2 to v3

Edit summary for version 3 by :

Version 2

2015-07-31, 23:41:12

Version 3

2015-07-31, 23:42:52

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"
)
Code
r := rand.New(rand.NewSource(time.Now().UnixNano()))
Comments bubble
r is of type *rand.Rand.
Demo URL
http://play.golang.org/p/o1XU6brwr7