views:

420

answers:

7

Hi everybody, I have this long and complex source code that uses a RNG with a fix seed.

This code is a simulator and the parameters of this simulator are the random values given by this RNG. When I execute the code in the same machine, no matter how many attempts I do the output is the same. But when I execute this code on two different machines and I compare the outputs of both the machines, they are different.

Is it possible that two different machines gives somehow different output using the same random number generator and the same seed?

The compiler version, the libraries and the OS are the same.

+7  A: 

It is certainly possible, as the RNG may be combining machine specific data with the seed, such as the network card address, to generate the random number. It is basically implementation specific.

Shane MacLaughlin
+4  A: 

If it's a pseudo random generator that uses nothing but the seed to produce a number sequence, then by definition they cannot be different. However, if the ones you're using are using something machine dependent to perturb the seed, or quite simply, a different algorithm, it's of course quite possible. Which implementation are you using, and if it's a standard library implementation, are they both the same version?

roe
The question states that libraries, compilers, and OS are the same.
Jonathan Leffler
Still - could be Linux/glibc/gcc with different floating-point settings.
MSalters
Knowing nothing about the generator, it could be accessing something specific to the machine in seeding.
David Thornley
A: 

Perhaps it's a little/big endian problem, or the code detects the processor in some way. Easiest way to do this would be to use breakpoints or similar debug routines to watch the seeding routines and the RNG itself at work.

schnaader
+5  A: 

As they do give different results it is obviously possible that they give different results. Easy-to-answer question, next!

Seriously: without knowing the source code to the RNG it’s hard to know whether you’re observing a bug or a feature. But it sounds like the RNG in question is using a second seed from somewhere else, e.g. the current time, or some hardware-dependent value like the network card’s MAC address.

Bombe
Not the current time, as it's producing the same results over and over again on his machine, but the MAC address is certainly a possibility.
gkrogers
A: 

It depends greatly on which RNG you are using. Things such like random(3) or the rand48(3) family are designed to return the same sequence when run with the same seed. Now, if the RNG you are using take /dev/random output, all bets are off and results will be different.

Keltia
+1  A: 

Yes. There are floating-point RNGs, for instance, whose results can depend on whether your CPU is properly implementing IEEE floats (not guranteed in ISO C++). Also, effects such as spilling 80 bits doubles to memory can influence results.

There is also some possibile confusion about the notion of a "seed". Some people define the seed as all input to set the initial state of the RNG. Others restrict it to only the explicit input in code, and exclude implicit input from e.g. HW sources or /dev/random.

MSalters
+2  A: 

If you need something that can be repeated from machine to machine, try the Boost Random Number Library.

Mark Ransom
+1 (because that's all I can do). In general, system RNGs often have problems, and going to Boost for a better one is often an excellent idea.
David Thornley