-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Open
Labels
docsThis change adds or pertains to documentationThis change adds or pertains to documentationrandomnessRandom number generation and the Random stdlibRandom number generation and the Random stdlib
Description
I'm having trouble setting the seed on worker tasks using Distributed
. If I set the seed and then get a random number in one remote call, the result is correct. If I set the seed and then get the random number in two remote calls, the random number is different each time.
MWE
using Distributed
addprocs(1)
@everywhere using Random
# works on main process
Random.seed!(1234); rand()
fetch(@spawnat 1 (Random.seed!(1234); rand()))
# works in one call
fetch(@spawnat 2 (Random.seed!(1234); rand()))
# doesn't work in two calls
fetch(@spawnat 2 Random.seed!(1234)); fetch(@spawnat 2 rand())
fetch(@spawnat 2 Random.seed!(1234)); fetch(@spawnat 2 rand())
Output:
0.32597672886359486
0.32597672886359486
0.32597672886359486
0.23226466961312875
0.11712298602126525
versioninfo()
Julia Version 1.9.3
Commit bed2cd540a1 (2023-08-24 14:43 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: macOS (arm64-apple-darwin22.4.0)
CPU: 12 × Apple M2 Max
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-14.0.6 (ORCJIT, apple-m1)
Threads: 1 on 8 virtual cores
Environment:
JULIA_EDITOR = code
JULIA_NUM_THREADS =
Metadata
Metadata
Assignees
Labels
docsThis change adds or pertains to documentationThis change adds or pertains to documentationrandomnessRandom number generation and the Random stdlibRandom number generation and the Random stdlib