1

I know that pseudo random generators are meant to be deterministic, i.e., when the same seed is used, they produce the same sequence of outputs. In practice, this is all true only when you are on the same platform, i.e., the same hardware, OS, etc.

I know that in some cases, however, when you run the same code on different platforms, you may get different answers (as briefly pointed out here: How to generate a repeatable random number sequence?).

As another example, this article studies some cause of such differences in the context of some neuro-imaging applications: http://journal.frontiersin.org/article/10.3389/fninf.2015.00012/abstract

My question is whether there is a general well-documented explanation for this phenomenon. Any other pointers are appreciated.

In other words, my concern is under what circumstances is the reproducibility of pseudo random generators jeopardized? And how can these situations be avoided (and truly guarantee cross-platform reproducibility)?

Community
  • 1
  • 1
Mahdi
  • 1,778
  • 1
  • 21
  • 35
  • "In practice, this is all true only when you are on the same platform, i.e., the same hardware, OS, etc." - not sure this is entirely a correct surmise. It's going to depend on your total environment - for example Java will provide well-defined PRNG (through provider spi interface) that will be properly repeatable across platforms, etc... – BadZen Apr 20 '15 at 14:47
  • So I guess a partial answer to "how can these situations be avoided" is to choose a dev environment with well defined PRNG semantics! – BadZen Apr 20 '15 at 14:48
  • Thanks BadZen. Do you know of your claim (of Java's PRNG semantics being well-defined) being documented somewhere? – Mahdi Apr 20 '15 at 14:52
  • @Mahdi [Java explicitly states in the JavaDocs what calculation they implement](http://docs.oracle.com/javase/8/docs/api/java/util/Random.html#next-int-). – pjs Apr 20 '15 at 15:03
  • 1
    Mahdi - There are two parts to this - the implementation of PRNG as bitstreams, and the semantics of floating point operations once you have them. Documentation for the first is at http://docs.oracle.com/javase/7/docs/api/java/util/Random.html - and documentation for the second part is http://en.wikipedia.org/wiki/Strictfp (intro) and in the language specification https://docs.oracle.com/javase/specs/ – BadZen Apr 20 '15 at 16:30
  • Of course none of this really helps you if you're using libraries built on underlying machine FP implementations, instead of Java. I'm not aware of any operating systems that make promises about FP semantics, and there is certainly no "standard" way of doing so even though there is a standard for FP. Such is the insanity of the numerical programmer's life... – BadZen Apr 20 '15 at 16:31
  • I also found this question, confirming your claim with regard to Java: http://stackoverflow.com/q/9151852/1545579 – Mahdi Apr 20 '15 at 21:36

1 Answers1

0

You are confused. PRNGs are, by definition, completely deterministic. They can't be otherwise, because they run on deterministic hardware. The same algorithm running on different machines will produce identical results.

Machines and OSs differ mainly because they use different algorithms or different seeding methods. If you want a PRNG that's identical between machines, just write it yourself so you know it's the same.

There are also lots of non-Pseudo RNGs that make use or hardware devices and other entropy sources that are non-deterministic: these include things like /dev/random, random.org, and others. Don't use these if you want reproducibility. DO use these if you want cryptographic security.

Lee Daniel Crocker
  • 12,927
  • 3
  • 29
  • 55
  • 3
    As OP states, he is fully aware how PRNG work wrt seeding. If you read the paper he posted, you'll see that the problem is with regard to the interpretation of pseudo-random bit streams as floating point numbers. Since floating point implementations vary wildly per platform, these packages can produce non-reproducible results over different platforms. – BadZen Apr 20 '15 at 16:25
  • As BadZen mentioned, I am aware of the idea of PRNG. The point is in the cases I mentioned, even the same seed produces different results on different platforms. – Mahdi Apr 20 '15 at 21:17
  • Is it the platform or the algorithm? I am not aware of two platforms that even claim to have the same PRNG, except where it is specified by the language (such as Python or Java). – Lee Daniel Crocker Apr 20 '15 at 21:20