Skip to content

Commit

Permalink
docs: global rand seed deprecated in go1.20
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mroth committed Feb 2, 2023
1 parent 06b4ed8 commit 2cfd796
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 7 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
)

func main() {
rand.Seed(time.Now().UTC().UnixNano()) // always seed random!

chooser, _ := weightedrand.NewChooser(
weightedrand.NewChoice('🍒', 0),
weightedrand.NewChoice('🍋', 1),
Expand Down
4 changes: 0 additions & 4 deletions examples/frequency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ package main
import (
"fmt"
"log"
"math/rand"
"time"

"github.com/mroth/weightedrand/v2"
)

func main() {
rand.Seed(time.Now().UTC().UnixNano()) // always seed random!

c, err := weightedrand.NewChooser(
weightedrand.NewChoice('🍒', 0),
weightedrand.NewChoice('🍋', 1),
Expand Down
2 changes: 1 addition & 1 deletion weightedrand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Example() {
*******************************************************************************/

func init() {
rand.Seed(time.Now().UTC().UnixNano())
rand.Seed(time.Now().UTC().UnixNano()) // only necessary prior to go1.20
}

const (
Expand Down

0 comments on commit 2cfd796

Please sign in to comment.