Skip to content
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

refactor: use rand.New(rand.NewSource) instead of deprecated rand.Seed #25279

Open
wants to merge 1 commit into
base: master-1.x
Choose a base branch
from

Conversation

chengshiwen
Copy link

Describe your proposed changes here.

  • I've read the contributing section of the project README.
  • Signed CLA (if not already signed).

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.

@chengshiwen chengshiwen changed the title Refactor: use rand.New(rand.NewSource) instead of deprecated rand.Seed refactor: use rand.New(rand.NewSource) instead of deprecated rand.Seed Sep 1, 2024
@chengshiwen
Copy link
Author

@davidby-influx @gwossum

@chengshiwen
Copy link
Author

Please review, thanks so much.
@bnpfeife @jdstrand @devanbenz

Copy link
Contributor

@davidby-influx davidby-influx left a comment

Choose a reason for hiding this comment

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

As I understand the new rand package, calling rand.New returns a generator based on the source provided in the call. That means that setting a new source does not affect the default source used by the top level functions like rand.Float64. If we are setting seeds explicitly, we need to use the *rand.Rand returned by rand.New to generate the values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants