]> Cypherpunks.ru repositories - gostls13.git/commit
math/rand: auto-seed global source
authorRuss Cox <rsc@golang.org>
Tue, 4 Oct 2022 16:20:18 +0000 (12:20 -0400)
committerGopher Robot <gobot@golang.org>
Tue, 25 Oct 2022 16:49:48 +0000 (16:49 +0000)
commit90a67d052e6dc3f9d522820ca60cc9862a8016ba
tree85daf9c53fedd5f705b3b38244be626916c2e758
parent4c9006e45f7c2ab51328868bf2894c3eba7ac3e6
math/rand: auto-seed global source

Implement proposal #54880, to automatically seed the global source.

The justification for this not being a breaking change is that any
use of the global source in a package's init function or exported API
clearly must be valid - that is, if a package changes how much
randomness it consumes at init time or in an exported API, that
clearly isn't the kind of breaking change that requires issuing a v2
of that package. That kind of per-package change in the position
of the global source is indistinguishable from seeding the global
source differently. So if the per-package change is valid, so is auto-seeding.

And then, of course, auto-seeding means that packages will be
far less likely to depend on the specific results of the global source
and therefore not break when those kinds of per-package changes
happen in the future.

Seed(1) can be called in programs that need the old sequence from
the global source and want to restore the old behavior.
Of course, those programs will still be broken by the per-package
changes just described, and it would be better for them to allocate
local sources rather than continue to use the global one.

Fixes #54880.

Change-Id: Ib9dc3307b97f7a45587a9cc50d81f919d3edc7ae
Reviewed-on: https://go-review.googlesource.com/c/go/+/443058
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
src/math/rand/auto_test.go [new file with mode: 0644]
src/math/rand/rand.go
src/runtime/stubs.go