optionally parametrize algorithms by a rand.Rand instead of relying on the default#17
Open
mbivert-ipsos wants to merge 1 commit intoccssmnn:masterfrom
Open
optionally parametrize algorithms by a rand.Rand instead of relying on the default#17mbivert-ipsos wants to merge 1 commit intoccssmnn:masterfrom
mbivert-ipsos wants to merge 1 commit intoccssmnn:masterfrom
Conversation
ccoVeille
reviewed
Jun 24, 2025
anneal.go
Outdated
Comment on lines
47
to
51
| Settings | ||
| // Random generator, overriding math/rand's default rand.Source when specified. | ||
| // This is in particular useful for tests predictibility, as since Go 1.24, | ||
| // rand.Seed() is a no-op; but still as effective with non-default Sources. | ||
| *rand.Rand |
Contributor
There was a problem hiding this comment.
you have a Settings here, so you have Settings.Rand ? as you defined Rand in Settings
no ?
Author
There was a problem hiding this comment.
yup, trailing from the first implementation, fixed
227beed to
2b0cafe
Compare
ccoVeille
reviewed
Jun 24, 2025
anneal.go
Outdated
Comment on lines
58
to
60
| if s.Rand == nil { | ||
| s.Rand = rand.New(rand.NewSource(time.Now().UnixNano())) | ||
| } |
Contributor
There was a problem hiding this comment.
Why not calling Setting.Init ?
Author
There was a problem hiding this comment.
erf, again, trailing from first implementation, fixed
…n the default since Go 1.24, rand.Seed() is a no-op. fixing the seed was convenient for code expecting predictable output (e.g. tests). supplying a rand.Rand with a specific Seed allows to recover the pre-1.24 behavior.
2b0cafe to
a08f39e
Compare
ccoVeille
approved these changes
Jun 24, 2025
| // Random generator, overriding math/rand's default rand.Source when specified. | ||
| // This is in particular useful for tests predictibility, as since Go 1.24, | ||
| // rand.Seed() is a no-op; but still as effective with non-default Sources. | ||
| *rand.Rand |
Contributor
There was a problem hiding this comment.
I would use an interface
This way rand could either math/rand, math/rand/v2, or anything that user needs, including something that is not random, that could be useful for test purpose
it's important to validate in tests that math/rand.Rand and math/rand/v2.Rand satisfies this interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
since Go 1.24, rand.Seed() is a no-op. fixing the seed was convenient for code expecting predictable output (e.g. tests). supplying a rand.Rand with a specific Seed allows to recover the pre-1.24 behavior.