gopasspw / gopass

The slightly more awesome standard unix password manager for teams
https://www.gopass.pw/
MIT License
5.84k stars 487 forks source link

[cleanup] Math/rand.Seed deprecated #2650

Open n4x2 opened 1 year ago

n4x2 commented 1 year ago

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 commented 1 year ago

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

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

dominikschulz commented 1 year ago

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

orangekame3 commented 1 year ago

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

dominikschulz commented 1 year ago

@orangekame3 Feel free to do so

orangekame3 commented 12 months ago

@dominikschulz Thank you. I've created a PR. Please check it out: https://github.com/gopasspw/gopass/pull/2675

lhardt commented 4 days ago

Hello @dominikschulz !

I see the last pull request on this issue is from last year, but I see the good-first-issue tag. Do you mind if I open my own PR?

AnomalRoil commented 4 days ago

@lhardt Please go ahead. It should be as simple as taking the previous PR and fixing the merge conflicts and then doing the changes that were requested in there if you want. Or you can try and do it your way too if you have another idea to do it.