# Different program outputs under the same Random.seed!

**URL:** <https://discourse.julialang.org/t/different-program-outputs-under-the-same-random-seed/43923>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 29, 2020, 9:41pm UTC](https://discourse.julialang.org/t/different-program-outputs-under-the-same-random-seed/43923 "2020-07-29T21:41:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ken\_Lin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ken_lin/32/14367_2.png) [@Ken\_Lin](https://discourse.julialang.org/u/Ken_Lin)\
**Post date:** [July 29, 2020, 9:41pm UTC](https://discourse.julialang.org/t/different-program-outputs-under-the-same-random-seed/43923/1 "2020-07-29T21:41:35Z")

</div>

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:

```julia
using C
Random.seed!(1234)
@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!

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [July 30, 2020, 7:08am UTC](https://discourse.julialang.org/t/different-program-outputs-under-the-same-random-seed/43923/2 "2020-07-30T07:08:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 30, 2020, 9:24am UTC](https://discourse.julialang.org/t/different-program-outputs-under-the-same-random-seed/43923/3 "2020-07-30T09:24:26Z")

</div>

> [@Ken\_Lin](#):
>
> What could be the reasons?

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).
