Skip to content

Commit

Permalink
chore: instance rand.Seed to rand.Source (#1233)
Browse files Browse the repository at this point in the history
The `rand.Seed` method is currently deprecated, use rand Replace with
the `NewSource` method.

```
// Deprecated: As of Go 1.20 there is no reason to call Seed with
// a random value. Programs that call Seed with a known value to get
// a specific sequence of results should use New(NewSource(seed)) to
// obtain a local random generator.
```

---------

Signed-off-by: Young Xu <[email protected]>
Co-authored-by: LinkinStars <[email protected]>
  • Loading branch information
xuthus5 and LinkinStars authored Jan 16, 2025
1 parent 774f4b3 commit 581f73c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/uid/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ type SnowFlakeID struct {
var snowFlakeIDGenerator *SnowFlakeID

func init() {
// todo
rand.Seed(time.Now().UnixNano())
node, err := snowflake.NewNode(int64(rand.Intn(1000)) + 1)
source := rand.NewSource(time.Now().UnixNano())
r := rand.New(source)
node, err := snowflake.NewNode(int64(r.Intn(1000)) + 1)
if err != nil {
panic(err.Error())
}
Expand Down

0 comments on commit 581f73c

Please sign in to comment.