Commit 55c71e6
authored
chore: replace deprecated api rand.Seed (#1363)
### Motivation
The Go 1.20 release deprecated the `rand.Seed` function, noting that programs should use the `rand.New(rand.NewSource(seed))` method instead. This change was made because using `rand.Seed` affects the global random number generator, which can lead to unexpected behavior in concurrent programs. By updating to the recommended API, we improve the code's forward compatibility and follow Go's best practices for random number generation.
### Modifications
Replaced all occurrences of `rand.Seed(time.Now().UnixNano())` with `rand.New(rand.NewSource(time.Now().UnixNano()))`
Updated variable assignments to use the new random generator instance where applicable
Maintained the same seed behavior (using current nanosecond time) but now with proper instance isolation
Verifying this change
Make sure that the change passes the CI checks.
This change is a trivial rework / code cleanup without any test coverage. The modification doesn't change the logical behavior of the code, only updates it to use the non-deprecated API.
---------
Signed-off-by: Young Xu <[email protected]>1 parent f9363eb commit 55c71e6
2 files changed
+6
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | 25 | | |
30 | 26 | | |
31 | 27 | | |
| |||
43 | 39 | | |
44 | 40 | | |
45 | 41 | | |
| 42 | + | |
46 | 43 | | |
47 | 44 | | |
48 | 45 | | |
49 | | - | |
| 46 | + | |
50 | 47 | | |
51 | 48 | | |
52 | 49 | | |
| |||
66 | 63 | | |
67 | 64 | | |
68 | 65 | | |
69 | | - | |
| 66 | + | |
70 | 67 | | |
71 | 68 | | |
72 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | 50 | | |
54 | | - | |
| 51 | + | |
55 | 52 | | |
56 | 53 | | |
57 | 54 | | |
| |||
111 | 108 | | |
112 | 109 | | |
113 | 110 | | |
114 | | - | |
| 111 | + | |
115 | 112 | | |
116 | 113 | | |
117 | 114 | | |
| |||
0 commit comments