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

proposal: Go 2: move math/rand to x/math/rand #24800

Closed
adamdecaf opened this issue Apr 10, 2018 · 4 comments
Closed

proposal: Go 2: move math/rand to x/math/rand #24800

adamdecaf opened this issue Apr 10, 2018 · 4 comments
Labels
FrozenDueToAge Proposal v2 An incompatible library change
Milestone

Comments

@adamdecaf
Copy link
Contributor

adamdecaf commented Apr 10, 2018

math/rand has several known and documented problems (see #21835) and it's easily mistaken for crypto/rand (see #20661). This is a proposal to move it out of the standard library, which would give several advantages.

  • Easier ability to implement other sources and tweak it's performance or space usage
  • Removal accidental use (when developer should have used crypto/rand)

The go fix tool could rewrite imports to x/math/rand or default to crypto/rand. There are real use cases for a deterministic generator (jitter, tests, etc) so we shouldn't remove it entirely. We should gather uses of math/rand that crypto/rand doesn't satisfy.

@gopherbot gopherbot added this to the Proposal milestone Apr 10, 2018
@adamdecaf adamdecaf changed the title proposal: Go2: move math/rand to x/math/rand proposal: Go 2: move math/rand to x/math/rand Apr 10, 2018
@mvdan mvdan added the v2 An incompatible library change label Apr 10, 2018
@ianlancetaylor
Copy link
Member

Are you suggesting that for Go 2 we not implement #21835, and instead move math/rand out of the standard library? Or do you think it would be OK to adopt #21835 for Go 2?

@ALTree
Copy link
Member

ALTree commented Apr 11, 2018

Easier ability to implement other sources and tweak it's performance or space usage

This same argument applies to literally every other package in the standard library; and yet you need to have something in it, right? : ) Unless go2 goes in the "move everything outside of the main repository" direction, I don't see how it could be reasonable to move a fundamental package like the one that generates random numbers out of stdlib, while still having a lot of other much less fundamental packages in it.

While it's true that we have been bitten in the past by the impossibility to fix fundamental deficiencies in the package's underling randomness source without breaking retro-compatibility, a new, clean implementation that fixes the most glaring issues with the package, like Rob proposed in #21835, could very well fit into the go2 standard library.

Removal accidental use (when developer should have used crypto/rand)

There's a (very prominent) warning at the top of the doc, in the package overview, about this:

For random numbers suitable for security-sensitive work, see the crypto/rand package.

And frankly, I doubt that a user that doesn't understand the difference between secure and non-secure random number generation will be able to write a cryptographically-secure application, even if we move math/rand outside the standard library.

@adamdecaf
Copy link
Contributor Author

adamdecaf commented Apr 11, 2018

@ianlancetaylor I have no problems with implementing #21835 in Go 2.

@ALTree I agree with you, but why does the stdlib even need to offer two random number generators? Do users care?

I (want to) assume anyone really needing math/rand over crypto/rand can find and use it from x/math/rand, but that the stdlib default is usable (and secure) for most uses.

@ianlancetaylor
Copy link
Member

Thanks. I'm going to close this issue in favor of #21835.

Discussions of why we need both math/rand and crypto/rand are perhaps best held on golang-dev.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Proposal v2 An incompatible library change
Projects
None yet
Development

No branches or pull requests

5 participants