❮ Random
❯
- Seed
- time.Now().Unix
Random with seed
- In order to generate different random numbers one needs to set the starting point by calling Seed.
- A common way to do that is to provide the number of seconds since the epoch.
examples/random-with-seed/random_with_seed.go
package main import ( "fmt" "math/rand" "time" ) func main() { fmt.Println(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano()) a := rand.Float64() fmt.Println(a) }
1586851169266458373 0.2296012220177759