# Distributed.@everywhere alters random generator state?

**URL:** <https://discourse.julialang.org/t/distributed-everywhere-alters-random-generator-state/101230>\
**Category:** General Usage\
**Tags:** distributed, random\
**Created:** [July 5, 2023, 11:10pm UTC](https://discourse.julialang.org/t/distributed-everywhere-alters-random-generator-state/101230 "2023-07-05T23:10:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pitsianis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pitsianis/32/26588_2.png) [@pitsianis](https://discourse.julialang.org/u/pitsianis)\
**Post date:** [July 5, 2023, 11:10pm UTC](https://discourse.julialang.org/t/distributed-everywhere-alters-random-generator-state/101230/1 "2023-07-05T23:10:48Z")

</div>

```julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.9.2 (2023-07-05)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia> using Random, Distributed

julia> Random.seed!(0); @everywhere (t = 2); rand(1)
1-element Vector{Float64}:
 0.6616126907308237

julia> Random.seed!(0); @everywhere (t = 2); rand(1)
1-element Vector{Float64}:
 0.6616126907308237

julia> Random.seed!(0); rand(1)
1-element Vector{Float64}:
 0.4056994708920292

julia> Random.seed!(0); rand(1)
1-element Vector{Float64}:
 0.4056994708920292

```

Is it expected for the `Distributed.@everywhere` to alter the random generator state?

---

<div class="post-metadata">

**Author:** ![pitsianis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pitsianis/32/26588_2.png) [@pitsianis](https://discourse.julialang.org/u/pitsianis)\
**Post date:** [July 5, 2023, 11:20pm UTC](https://discourse.julialang.org/t/distributed-everywhere-alters-random-generator-state/101230/2 "2023-07-05T23:20:32Z")

</div>

```julia
julia> using Random, Distributed

julia> Random.seed!(0); rand(1)
1-element Vector{Float64}:
 0.4056994708920292

julia> Random.seed!(0); rand(1)
1-element Vector{Float64}:
 0.4056994708920292

julia> Random.seed!(0); pmap(x -> x+1, 1:10); rand(1)
1-element Vector{Float64}:
 0.6616126907308237

julia> Random.seed!(0); pmap(x -> x+1, 1:10); rand(1)
1-element Vector{Float64}:
 0.6616126907308237

```

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [July 6, 2023, 9:04am UTC](https://discourse.julialang.org/t/distributed-everywhere-alters-random-generator-state/101230/3 "2023-07-06T09:04:37Z")

</div>

If you care about that, you should perhaps supply the random generator to `rand` explicitly. Maybe even use [StableRNGs](https://github.com/JuliaRandom/StableRNGs.jl).
