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

[cleanup] Math/rand.Seed deprecated #2650

Open
n4x2 opened this issue Sep 6, 2023 · 5 comments
Open

[cleanup] Math/rand.Seed deprecated #2650

n4x2 opened this issue Sep 6, 2023 · 5 comments
Labels
good-first-issue Good for beginners starting to contribute help-wanted
Milestone

Comments

@n4x2
Copy link

n4x2 commented Sep 6, 2023

Summary

Since Go 1.20 release, math/rand.Seed is marked "Deprecated"

Looks like five instances to consider updating:

find . -name "*.go" -type f -print | xargs grep .Seed
./pkg/pwgen/pwgen_test.go:      mrand.Seed(1789)
./pkg/pwgen/rand.go:    rand.Seed(time.Now().Unix() + int64(os.Getpid()+os.Getppid()))
./pkg/fsutil/fsutil.go: rand.Seed(time.Now().UnixNano())
./pkg/gitconfig/config_test.go: rand.Seed(time.Now().Unix())
./internal/action/binary_test.go:       rand.Seed(42)
@dominikschulz dominikschulz self-assigned this Sep 6, 2023
@dominikschulz
Copy link
Member

Usually "Deprecated" just means it's finally stable ;)

But I'll check what the recommendation is these days.

@dominikschulz
Copy link
Member

  • pkg/pwgen/rand.go This one can Go away once we don't need to support Go 1.20 anymore.
  • pkg/fsutil/fsutil.go Same here.

For the test files we actually rely on detemernistic output, so we will need some more changes. We need to introduce a global variable with a local generator and seed it like this New(NewSource(seed)). See https://pkg.go.dev/math/rand#Seed

@dominikschulz dominikschulz added this to the 1.x.x milestone Sep 7, 2023
@dominikschulz dominikschulz added help-wanted good-first-issue Good for beginners starting to contribute labels Sep 7, 2023
@dominikschulz dominikschulz changed the title Math/rand.Seed deprecated [cleanup] Math/rand.Seed deprecated Sep 7, 2023
@dominikschulz dominikschulz removed their assignment Sep 7, 2023
@orangekame3
Copy link

@dominikschulz
Hi, I'd like to take on this issue if that's okay.

@dominikschulz
Copy link
Member

@orangekame3 Feel free to do so

@orangekame3
Copy link

@dominikschulz
Thank you. I've created a PR. Please check it out:
#2675

@AnomalRoil AnomalRoil linked a pull request Jan 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good-first-issue Good for beginners starting to contribute help-wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants