TL;DR:
A program draws the same random seed when started twice simultaneously. How did it happen?
Details
I'm running an MCMC statistical analysis, so I execute the program (phylobayes) twice to get 2 independent replicates.
For doing so, my shell script detaches each replicate run, like this (schematically):
pb -d "inputdata" "replicate1" &
pid1=$!
pb -d "inputdata" "replicate2" &
pid2=$!
wait "$pid1"
wait "$pid2"
(Then, this script was submitted to a computing cluster (Debian 10) using slurm sbatch
).
But many of my runs (like 30%) were started with the same random seed! as shown from the log files.
Phylobayes uses C++ Random::initRandom()
command. [EDIT: actually, as pointed out this function has a custom definition inside the package].
Can it technically occur that the same random seed is taken? Does it use /dev/random or /dev/urandom ?
If yes, I will just insert a sleep
command between starts;
if not, I have to understand what dumb mistake I made, but I don't see what it can be...
Random::initRandom()
in C++. There's one defined in that code, which does use the current time as the seed: github.com/bayesiancook/phylobayes/blob/…