This is an automated email from the ASF dual-hosted git repository.
linkinstar pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/answer.git
The following commit(s) were added to refs/heads/dev by this push:
new 581f73c8 chore: instance rand.Seed to rand.Source (#1233)
581f73c8 is described below
commit 581f73c85765c9e1b66d8942f1af878cf459a721
Author: Young Xu <[email protected]>
AuthorDate: Thu Jan 16 11:16:57 2025 +0800
chore: instance rand.Seed to rand.Source (#1233)
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]>
---
pkg/uid/id.go | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/pkg/uid/id.go b/pkg/uid/id.go
index 3614ea5e..f2c72bae 100644
--- a/pkg/uid/id.go
+++ b/pkg/uid/id.go
@@ -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())
}