# Random seed in multi-core parallel running

**URL:** <https://discourse.julialang.org/t/random-seed-in-multi-core-parallel-running/41017>\
**Category:** General Usage\
**Tags:** question\
**Created:** [June 8, 2020, 8:29pm UTC](https://discourse.julialang.org/t/random-seed-in-multi-core-parallel-running/41017 "2020-06-08T20:29:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jing\_Zhang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jing_zhang/32/13737_2.png) [@Jing\_Zhang](https://discourse.julialang.org/u/Jing_Zhang)\
**Post date:** [June 8, 2020, 8:29pm UTC](https://discourse.julialang.org/t/random-seed-in-multi-core-parallel-running/41017/1 "2020-06-08T20:29:23Z")

</div>

Dear Julia Users,

I was using @distributed to run 1000 replicates of simulations across 100 cores. How should I set the random seed across these cores to make simulation results reproducible? We need to make sure different cores start with a different seed and there are no replicates / overlap across different cores.

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![simonbyrne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonbyrne/32/19_2.png) [@simonbyrne](https://discourse.julialang.org/u/simonbyrne)\
**Post date:** [June 8, 2020, 9:01pm UTC](https://discourse.julialang.org/t/random-seed-in-multi-core-parallel-running/41017/2 "2020-06-08T21:01:14Z")

</div>

A simple option is seed based on some function of your replicate index and `myid()`:

```julia
using Distributed
@everywhere using Random
@everywhere Random.seed!(1000*replicate_idx + myid())

```

---

<div class="post-metadata">

**Author:** ![Jing\_Zhang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jing_zhang/32/13737_2.png) [@Jing\_Zhang](https://discourse.julialang.org/u/Jing_Zhang)\
**Post date:** [June 9, 2020, 1:26am UTC](https://discourse.julialang.org/t/random-seed-in-multi-core-parallel-running/41017/3 "2020-06-09T01:26:02Z")

</div>

Thanks! It seems

```julia
@distributed for replicate_idx=1:1000
Random.seed!(replicate_idx) 
...
end 

```

should be fine no matter how many random procedures in each replicate of simulation. 🙂

---

<div class="post-metadata">

**Author:** ![simonbyrne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonbyrne/32/19_2.png) [@simonbyrne](https://discourse.julialang.org/u/simonbyrne)\
**Post date:** [June 9, 2020, 2:41am UTC](https://discourse.julialang.org/t/random-seed-in-multi-core-parallel-running/41017/4 "2020-06-09T02:41:35Z")

</div>

Ah, I think I misunderstood: yes, if you have 1000 replicates that you’re sharding out across various processes, that should be the simplest option.
