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

math/rand/v2 is an unsupported randomness source #9

Open
awnumar opened this issue Aug 14, 2024 · 1 comment
Open

math/rand/v2 is an unsupported randomness source #9

awnumar opened this issue Aug 14, 2024 · 1 comment

Comments

@awnumar
Copy link

awnumar commented Aug 14, 2024

With the release of Go 1.22, there's a new version of the math/rand package.

At present, it's not possible to use a randomness source created by v2 with jitterbug, e.g.

t := jitterbug.New(1 * time.Minute, jitterbug.Norm{
	Source: mrandv2.New(...),
	Stdev: 1 * time.Second,
})

this fails because math/rand/v2.Rand != math/rand.Rand.

This isn't a huge issue, but thought it's worth flagging anyways. Perhaps one way to solve this would be to update implementations of the Jitter interface to accept an interface instead of *math.Rand

type RandomSource interface {
	NormFloat64() float64
        ...
}

type Norm struct {
	Source      RandomSource
	Mean, Stdev time.Duration
}

or maybe even:

type RandomSource interface {
	mrand.Rand | mrandv2.Rand
}

though I'm not sure how well that'd work with pointer receivers as I've not tested it.

@lthibault
Copy link
Owner

Thanks for flagging this! Proposed solution sounds good to me as well.

Any chance you could open a PR for this? I'll happily merge it in.

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

No branches or pull requests

2 participants