Skip to content

all: migrate from math/rand to math/rand/v2#270

Merged
kaworu merged 1 commit into
cilium:mainfrom
IstvanCsVarga:migrate-rand-v2
Mar 25, 2026
Merged

all: migrate from math/rand to math/rand/v2#270
kaworu merged 1 commit into
cilium:mainfrom
IstvanCsVarga:migrate-rand-v2

Conversation

@IstvanCsVarga
Copy link
Copy Markdown
Contributor

Fixes: #263

Migrate the random number generation from math/rand to math/rand/v2 across all three modules (main, flow, cmd).

The v2 package uses the ChaCha8 generator which provides improved performance and better scalability. It also removes the need for manual seeding, so the init() call in rand.go is deleted.

API changes applied:

  • rand.Intn -> rand.IntN
  • rand.Int63n -> rand.Int64N
  • rand.Read -> crypto/rand.Read (removed from v2)
  • rand.Seed -> deleted (v2 auto-seeds)

The staticcheck SA1019 lint suppressions for the deprecated rand.Read and rand.Seed calls are also removed, as noted by the existing TODO comment in .golangci.yml.

All three modules tests pass locally.

Migrate the random number generation from math/rand to math/rand/v2
across all three modules (main, flow, cmd).

The v2 package uses the ChaCha8 generator which provides improved
performance and better scalability. It also removes the need for
manual seeding, so the init() call in rand.go is no longer needed.

API changes applied:
- rand.Intn -> rand.IntN
- rand.Int63n -> rand.Int64N
- rand.Read -> crypto/rand.Read (removed from v2)
- rand.Seed -> deleted (v2 auto-seeds)

The staticcheck SA1019 lint suppressions for the deprecated rand.Read
and rand.Seed calls are also removed, as noted by the existing TODO
comment in .golangci.yml.

Fixes: cilium#263

Signed-off-by: Istvan Csaba Varga <istvan.csaba.varga@accenture.com>
@kaworu kaworu self-requested a review March 24, 2026 14:59
Copy link
Copy Markdown
Member

@kaworu kaworu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @IstvanCsVarga 👋 and thank you for the PR!

I'm blocking it momentarily because I wish to coordinate this change with #271, i.e. discuss which one we should merge first, because they will definitely be conflicting. The patch itself LGTM.

@kaworu kaworu added the enhancement New feature or request label Mar 24, 2026
Copy link
Copy Markdown
Member

@rolinh rolinh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for your contribution!

Copy link
Copy Markdown
Member

@kaworu kaworu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge this one as it is ready! I'll rebase #271 on top and resolve the conflicts.

@kaworu kaworu merged commit 9ac0640 into cilium:main Mar 25, 2026
6 checks passed
@kaworu kaworu mentioned this pull request Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate to math/rand/v2

3 participants