-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
define
Random.GLOBAL_RNG = TaskLocalRNG()
(#51388)
`GLOBAL_RNG` is a relic from pre-v1.3 when our global RNG was not thread-safe: ``` const GLOBAL_RNG = MersenneTwister() ``` `GLOBAL_RNG` was never really specified, but was referred to in docstrings (of `rand` etc.), and people had to use it in packages in order to provide a default RNG to their functions. So we have to keep defining `Random.GLOBAL_RNG` for the time being. In v1.3, we didn't have anymore a unique global RNG, but instead one per thread; in order to keep code using `GLOBAL_RNG` working, we got this new definition as a clever hack: ``` struct _GLOBAL_RNG <: AbstractRNG end const GLOBAL_RNG = _GLOBAL_RNG() ``` I.e. `GLOBAL_RNG` is just a "handle", which refers to the actual threaded-RNG when passed to `rand` functions. This entails defining most functions taking a `default_rng()` to also accept `_GLOBAL_RNG`. See #41123, and #41235 which is not even merged. But since v1.7, we have `Random.default_rng()` (our now official way to refer to the default RNG) returning `TaskLocalRNG()`, which is itself a "handle" (singleton). So we can as well redefine `GLOBAL_RNG` to be `TaskLocalRNG()` instead of `_GLOBAL_RNG()`, with the advantage that all the relevant methods are already defined for `TaskLocalRNG`. The only expected difference in behavior is `seed!(GLOBAL_RNG, seed)`, which previously would update `Random.GLOBAL_SEED` (a hack used by `@testset`), but now is equivalent to `seed!(TaskLocalRNG(), seed)`, which doesn't update this global seed. This precise behavior was never documented (`GLOBAL_SEED` is purely internal), so this should be fine.
- Loading branch information
Showing
6 changed files
with
40 additions
and
86 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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