Skip to content

Commit 2cfd796

Browse files
committed
docs: global rand seed deprecated in go1.20
The math/rand package now automatically seeds the global random number generator with a random value, and the top-level Seed function has been deprecated.
1 parent 06b4ed8 commit 2cfd796

File tree

3 files changed

+1
-7
lines changed

3 files changed

+1
-7
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import (
2020
)
2121

2222
func main() {
23-
rand.Seed(time.Now().UTC().UnixNano()) // always seed random!
24-
2523
chooser, _ := weightedrand.NewChooser(
2624
weightedrand.NewChoice('🍒', 0),
2725
weightedrand.NewChoice('🍋', 1),

examples/frequency/main.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ package main
33
import (
44
"fmt"
55
"log"
6-
"math/rand"
7-
"time"
86

97
"github.com/mroth/weightedrand/v2"
108
)
119

1210
func main() {
13-
rand.Seed(time.Now().UTC().UnixNano()) // always seed random!
14-
1511
c, err := weightedrand.NewChooser(
1612
weightedrand.NewChoice('🍒', 0),
1713
weightedrand.NewChoice('🍋', 1),

weightedrand_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func Example() {
3434
*******************************************************************************/
3535

3636
func init() {
37-
rand.Seed(time.Now().UTC().UnixNano())
37+
rand.Seed(time.Now().UTC().UnixNano()) // only necessary prior to go1.20
3838
}
3939

4040
const (

0 commit comments

Comments
 (0)