# Disable global RNG

**URL:** <https://discourse.julialang.org/t/disable-global-rng/20690>\
**Category:** General Usage\
**Created:** [February 12, 2019, 3:11am UTC](https://discourse.julialang.org/t/disable-global-rng/20690 "2019-02-12T03:11:31Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [February 12, 2019, 7:57am UTC](https://discourse.julialang.org/t/disable-global-rng/20690/5 "2019-02-12T07:57:10Z")

</div>

If you intend to make the code multithreaded, it’s good practice to use the RNG version, since you’ll run into problems otherwise. See [this post](https://discourse.julialang.org/t/running-for-loop-in-parallel-and-appending-result-to-vector/20487/16) for an example of how to obtain an independent RNG per thread. (Also scroll up in the post to see the type of problems that can occur otherwise.)

As for disabling the global RNG, you could do something like this:

```julia
julia> rand(1, 4)
1×4 Array{Float64,2}:
 0.305565 0.252981 0.639368 0.759004

julia> Base.rand(dims::Integer...) = throw(ErrorException("Disabled. Use rand(rng, dims) instead."))

julia> rand(1, 4)
ERROR: Disabled. Use rand(rng, dims) instead.

```

(Note: There are other `rand` methods too that you’d need to redefine.) However, use this with care: it changes `rand` globally, so it won’t just affect your code.

---

_[View the full topic](https://discourse.julialang.org/t/disable-global-rng/20690)._
