Skip to content

Commit 0cda5e4

Browse files
committed
Merge branch 'tumdum-patch-1' of https://github.com/tumdum/til into tumdum-tumdum-patch-1
Conflicts: go/not-so-random.md
2 parents a3a975b + 1c09358 commit 0cda5e4

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

go/not-so-random.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
# Not So Random
22

3-
Go's `rand` package makes it easy to generate all sorts of pseudo-random numbers.
4-
5-
What they don't tell you though is that the default seed is `1`. They [do
6-
tell you that the numbers are pseudo-random and that you need to use the
7-
`Seed` function to initialize the default source if different behavior is
8-
required for each run](https://golang.org/pkg/math/rand/), though. So if you
9-
write a program like so:
3+
Go's `rand` package makes it easy to generate all sorts of pseudo-random
4+
numbers. So if you write a program like so:
105

116
```go
127
package main
@@ -31,8 +26,9 @@ and then run it, you will get output like:
3126
three
3227
```
3328

34-
and any subsequent runs of the program will continue to produce `three`. Not
35-
exactly what we are looking for.
29+
and any subsequent runs of the program will continue to produce `three`. This
30+
is because the default seed for global functions in `math/rand` is
31+
[specified](https://golang.org/pkg/math/rand/#Seed) as `1`.
3632

3733
If you want your program to be a little less predictable, you will want to
3834
seed it yourself, perhaps with the current time, instead of `1`. Try adding

0 commit comments

Comments
 (0)