JuliaLang/julia — pull request #9273 by rfourquet (2014-12-08 10:52:38+00:00)
Title: export globalRNG()

When a user adds a `rand!` method for her objects, she may want to have the `rng` object default to the global one, e.g:
```
Base.rand(rng::AbstractRNG, ::Type{MyObject}) = MyObject(rand(rng))
# no need to define Base.rand(::Type{MyObject})
Base.rand!(rng::AbstractRNG, x::MyObject) = (x.field = rand(rng); x)
Base.rand!(x::MyObject) = rand!(globalRNG(), x)
```
For this simple case, we could simply unconstrain the `rand!` methods which currently are `rand!(A::AbstractArray)` and `rand!(A::AbstractArray, r::AbstractArray)` by letting `A` be anything, but I still think that exporting `globalRNG()` is needed for more complicated cases (i.e. more parameters need to be passed to `rand[!]`).

We could directly export the global variable itself, but I feel that with multi-threading, we would have one such global variable per thread to avoid synchronization, and then `globalRNG()` would return this thread-local "global" RNG object. But I don't know much these questions, I can be wrong.