# Random seeds in parallel computing

**URL:** <https://discourse.julialang.org/t/random-seeds-in-parallel-computing/46899>\
**Category:** General Usage\
**Tags:** parallel\
**Created:** [September 19, 2020, 8:06am UTC](https://discourse.julialang.org/t/random-seeds-in-parallel-computing/46899 "2020-09-19T08:06:30Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [September 19, 2020, 9:26am UTC](https://discourse.julialang.org/t/random-seeds-in-parallel-computing/46899/4 "2020-09-19T09:26:07Z")

</div>

> [@AAL](#):
>
> Why does specifying a single random seed work and why do I get the same result? I thought if two parallel processes accessed and modified the state of the same random number generator, I would get an error or at least a different result since it is accessed in a different order.

This I can’t answer and it seems to be complex. See this old discussion:

> <https://github.com/JuliaLang/julia/issues/94>
>
> How should parallel RNG be addressed? Codes that do parallel RNG:
> 
> This is an MP…I code that does not seem to be maintained:
> http://sprng.cs.fsu.edu/
> 
> A derivative of Mersenne Twister:
> http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/DC/dc.html
> 
> At the very least,when randomize() is called, it should include the processor's number along with time to select a different seed on every processor.

And this one not so old:

> [@Brew a Parallel RNG?](https://discourse.julialang.org/t/brew-a-parallel-rng/30286):
>
> RNGs cannot be parallelized without modification, as the effectiveness of the randomness representation ceases if the sequences are related. Previous discussions have been found from But can we use some alternative solutions? Consider some ancient algorithms that are probably not in use nowadays(most written from the book Numerical Analysis by T. Sauer) # rng #random number generators #Computers are not capable of generating true random numbers #but can generate sequences with statistical …

What you actually need now is different random numbers for each worker but reproducible… (still looking)

This looks good:

```julia
using Distributed
addprocs(4)
@everywhere using SharedArrays, Random

A = SharedArray{Float64}(10,10)
@everywhere Random.seed!(myid())
@sync @distributed for i in 1:10
    A[:,i] = rand(10)
end

```

---

_[View the full topic](https://discourse.julialang.org/t/random-seeds-in-parallel-computing/46899)._
