11
$\begingroup$

If I use

SeedRandom[12345]
RandomReal[{0,1},100]

I get the same random numbers on two versions of Mathematica: 10.4.1.0 on Windows 10 and 11.1.1.0 on Windows 7.

But does the same seed get the same set of random numbers on OS X and flavors of Linux?

$\endgroup$
  • 2
    $\begingroup$ Yes, the default algorithm is the same since some fairly old version. (A cellular automaton based one.) No, I don't have proof or a reference ready for you :( $\endgroup$ – Szabolcs Oct 11 '17 at 19:56
  • 1
    $\begingroup$ As an example, RandomReal[{0, 1}, 3] with SeedRandom[12345] gives {0.121246, 0.329922, 0.782753} on OS X, mathematica 11.0.0 $\endgroup$ – egwene sedai Oct 11 '17 at 19:57
  • 1
    $\begingroup$ Same on a Raspberry Pi too (which is 32-bit). $\endgroup$ – Szabolcs Oct 11 '17 at 20:01
  • 7
    $\begingroup$ I believe it has been platform independent for many years now, possibly as far back as version 6 or so. $\endgroup$ – Daniel Lichtblau Oct 11 '17 at 20:47
  • $\begingroup$ Thanks to all. This is good to know. I'll certainly start setting the random number seed in all of my future answers that involve random samples. $\endgroup$ – JimB Oct 12 '17 at 4:03
9
$\begingroup$

Turning Daniels comment into an answer:

Random things with a fixed seed is platform-independent for many versions. The feature is implemented possibly since version 6.

I tested

SeedRandom[12345]
RandomReal[{0, 1}, 3]

with version 11.2 on Linux and get the same output as provided by egwene sedai for OSX with version 11.0

{0.121246, 0.329922, 0.782753}

I've tested this also on version 2.2 on XP 32 bit (1993) and on 11.2 on windows 7 64 bit (2017). They also give same result. I do not have Mathematica version 1.0 to test this on. Version 2.2 did not have RandomReal yet. So had to use loop to generate 3 numbers.

0.214347
0.539981
0.0875722

Mathematica graphics

Mathematica graphics

But also noticed that Random[Real, {0, 1}] gives different random from RandomReal[{0, 1}]

Mathematica graphics

$\endgroup$
  • 1
    $\begingroup$ As an addendum: it is often a good idea to enclose any operations involving seeding in a BlockRandom[], if you're concerned about interfering with the current random stream being used. As a typical example: suppose you are running a long Monte Carlo job, and in the middle of it, you need to generate a few random numbers unrelated to the Monte Carlo operation. You will then need to wrap that quick job in a BlockRandom[] so that the stream being used for the long job remains uninterrupted. $\endgroup$ – J. M. will be back soon Oct 12 '17 at 13:19
  • 1
    $\begingroup$ Older versions with Random will not be fully platform independent. Random may have become platform independent by version 5, I'm not sure. But that involved addressing some issues in 32 vs 64 bit platforms and also in endianness. $\endgroup$ – Daniel Lichtblau Oct 12 '17 at 17:57
  • $\begingroup$ @Daniel, if memory serves, the current Method -> "Legacy" was the version 5 iteration, and versions before that didn't even have the cellular-automaton method, and just used plain "subtract-with-borrow". $\endgroup$ – J. M. will be back soon Oct 12 '17 at 20:32
  • $\begingroup$ @j.M. Not quite. A CA was used for some things, I think including machine reals. Somewhat different innards, it used rule 30 and I think the current one uses a different rule. $\endgroup$ – Daniel Lichtblau Oct 12 '17 at 23:13
  • $\begingroup$ @J.M. Let me emend that. Random used (and probably still uses) rule 30 for machine integers (not reals) and bignum reals. SWB was used for big ints and machine reals. Go figure. $\endgroup$ – Daniel Lichtblau Oct 13 '17 at 4:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.