Skip to content

refactor(internal/bytesconv): replace rand usage with crypto/rand and rand.New #4259

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

Merged
merged 1 commit into from
Jun 9, 2025

Conversation

1911860538
Copy link
Contributor

@1911860538 1911860538 commented Jun 6, 2025

This commit refactors random usage to follow current best practices in Go 1.20+:

  • Replaced usage of math/rand.Read, which is deprecated, with crypto/rand.Read.
    As per the deprecation notice, crypto/rand.Read is more appropriate for almost all use cases.

  • Replaced rand.NewSource(time.Now().UnixNano()) with rand.New(rand.NewSource(time.Now().UnixNano())).
    rand.NewSource returns a bare Source which lacks convenience methods like Intn, Float64, etc.
    Wrapping it with rand.New provides a complete and idiomatic *rand.Rand object.

Copy link

codecov bot commented Jun 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.92%. Comparing base (3dc1cd6) to head (1a45951).
Report is 131 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4259      +/-   ##
==========================================
- Coverage   99.21%   98.92%   -0.30%     
==========================================
  Files          42       44       +2     
  Lines        3182     3434     +252     
==========================================
+ Hits         3157     3397     +240     
- Misses         17       26       +9     
- Partials        8       11       +3     
Flag Coverage Δ
?
--ldflags="-checklinkname=0" -tags sonic 98.85% <ø> (?)
-tags go_json 98.85% <ø> (?)
-tags nomsgpack 98.90% <ø> (?)
go-1.18 ?
go-1.19 ?
go-1.20 ?
go-1.21 ?
go-1.23 98.92% <ø> (?)
go-1.24 98.92% <ø> (?)
macos-latest 98.92% <ø> (-0.30%) ⬇️
ubuntu-latest 98.92% <ø> (-0.30%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@1911860538 1911860538 force-pushed the internal/bytesconv branch from 8887206 to a261a1d Compare June 6, 2025 09:51
@1911860538 1911860538 force-pushed the internal/bytesconv branch from a261a1d to 1a45951 Compare June 6, 2025 09:54
@1911860538 1911860538 changed the title refactor(internal/bytesconv): replace rand usage with crypto/rand and rand.Int63 refactor(internal/bytesconv): replace rand usage with crypto/rand and rand.New Jun 6, 2025
@appleboy appleboy added this to the v1.11 milestone Jun 9, 2025
@appleboy appleboy merged commit 77d70e5 into gin-gonic:master Jun 9, 2025
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants