-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
chore: use math/rand/v2 instead of math/rand #7413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ import ( | |
| "encoding/hex" | ||
| "encoding/json" | ||
| "fmt" | ||
| weakrand "math/rand" | ||
| weakrand "math/rand/v2" | ||
| "net/http" | ||
| "strings" | ||
| "sync" | ||
|
|
@@ -244,7 +244,7 @@ func (c *Cache) makeRoom() { | |
| // strategy; generating random numbers is cheap and | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 CRITICAL - Off-by-one error in cache eviction loop condition Category: bug Description: Suggestion: Confidence: 95% |
||
| // ensures a much better distribution. | ||
| //nolint:gosec | ||
| rnd := weakrand.Intn(len(c.cache)) | ||
| rnd := weakrand.IntN(len(c.cache)) | ||
| i := 0 | ||
| for key := range c.cache { | ||
| if i == rnd { | ||
|
Comment on lines
+247
to
250
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 HIGH - Inefficient O(n*m) cache eviction with repeated map traversals Category: performance Description: Suggestion: Confidence: 85% |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ import ( | |
| "errors" | ||
| "fmt" | ||
| "io" | ||
| weakrand "math/rand" | ||
| weakrand "math/rand/v2" | ||
| "mime" | ||
| "net/http" | ||
| "sync" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 MEDIUM - Zero-initialized random seed produces deterministic test data
Agent: go
Category: quality
Description:
Using 'rand.NewChaCha8([32]byte{})' with a zero seed produces identical test data on every run. While this may be intentional for reproducibility, the test name suggests testing with varied data.
Suggestion:
If determinism is intended, add a comment explaining the choice. If varied data is desired, use a non-zero or time-based seed.
Confidence: 65%
Rule:
qual_misleading_names_goReview ID:
9bac5f9f-38e7-46a1-add2-7c064de630b1Rate it 👍 or 👎 to improve future reviews | Powered by diffray