Different program outputs under the same Random.seed!

I have a Julia program that sometimes produces different results even if I set Random.seed!(1234). What could be the reasons?

Here is one possible reason I have found: In my program, I’m using a function c(x) from a package C I installed. This function also could produce slightly different results (say, a difference of 10^(-8)) for the same input x and the same Random.seed!. What I did was something like the following:

using C
@show c(x)

Is it because Random.seed! can’t control the result of the function c? Or is it due to some other numerical reasons?

Thank you!

What is this package C? (I couldn’t find it anywhere)

There are many reasons why c(x) could be independent of the seed,
it could call internally some python, FORTRAN or C code, which is not controlled by the Julia seed.

Even pure Julia code could possibly generate it’s own random numbers internally. (However, I would expect that most packages don’t do that.)

So, without knowing more about the package C it is difficult to answer.


Pretty much anything, depending on what that package C does (race conditions in threads, calling external code, initializing it its own RNGs, …).

I would debug this by comparing results are various checkpoints in c.

That said, I don’t think it makes too much sense to worry too much about exact reproducibility of results using randomness; the fact that your numbers come from a particular RNG should not matter too much (if it does, the algorithm is problematic).

1 Like