From f8416d5de018e4fecb7bc9e58a59b138a0e9235e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20F=20R=C3=B8dseth?= Date: Wed, 10 Feb 2016 12:44:04 +0100 Subject: [PATCH] Correct random to pseudo-random. Add information. --- go/not-so-random.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/go/not-so-random.md b/go/not-so-random.md index 6ac32cb..dd66f74 100644 --- a/go/not-so-random.md +++ b/go/not-so-random.md @@ -1,8 +1,8 @@ # Not So Random -Go's `rand` package makes it easy to generate all sorts of random numbers. -What they don't tell you though is that the default seed is `1`. So if you -write a program like so: +Go's `rand` package makes it easy to generate all sorts of pseudo-random numbers. + +What they don't tell you though is that the default seed is `1`. They [do tell you that the numbers are pseud-random and that you need to use the Seed function to initialize the default source if different behavior is required for each run](https://golang.org/pkg/math/rand/), though. So if you write a program like so: ```go package main @@ -35,7 +35,7 @@ seed it yourself, perhaps with the current time, instead of `1`. Try adding the following to the beginning of the `main` function: ```go -rand.Seed( time.Now().UTC().UnixNano()) +rand.Seed(time.Now().UTC().UnixNano()) ``` You'll also want to import the `time` package. @@ -43,4 +43,4 @@ You'll also want to import the `time` package. Things should *appear* to be a bit more random now. source: [Jake Worth](https://twitter.com/jwworth) and -[Stackoverflow](http://stackoverflow.com/questions/12321133/golang-random-number-generator-how-to-seed-properly) +[Stackoverflow](http://stackoverflow.com/questions/12321133/golang-random-number-generator-how-to-seed-properly)