views:

46

answers:

2

If I use the Random number generator function in different programming languages and I chose the same seed .. Do they have to give me the same random numbers ?

for example I used Java and Perl ... gave different numbers.

+2  A: 

No, unless the two languages happen to use the same algorithm.

SLaks
I think even different implementations of the same language may yield different results.
S.C. Madsen
@S.C.: Depending on the language and its spec.
SLaks
..or the same Operating System API call.
T.E.D.
@T.E.D.: Unless the OS changes its algorithm, or you switch to a different OS.
SLaks
A: 

Portability across languages is one reason to use your own random number generator. This article gives a very small random number generator whose algorithm has been vetted by experts. You can easily port the generator to any language that supports basic operations on 32-bit unsigned integers. Every implementation should return the same sequence of outputs given the same seeds.

John D. Cook