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

Upgrade rand package to use math/rand or math/rand/v2 #107

Open
sjsanc opened this issue Feb 13, 2025 · 1 comment
Open

Upgrade rand package to use math/rand or math/rand/v2 #107

sjsanc opened this issue Feb 13, 2025 · 1 comment

Comments

@sjsanc
Copy link

sjsanc commented Feb 13, 2025

The rand package uses the math/crypto package from the standard library. The random number generator from crypto is meant to generate secure numbers, and is therefore much slower than math/rand/v2, or even math/rand.

math/rand/v2 was added in 1.22 (we're on 1.23).

It's also a simpler implementation.

// Using math/rand/v2
func numberMathRandV2() (int64, error) {
	return randv2.Int64(), nil
}
@kashifkhan0771
Copy link
Owner

Great finding @sjsanc ❤️

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