Page 1 of 1

RandomSeed across versions and platforms

Posted: Fri Mar 09, 2012 2:38 am
by kenmo
Question:

I want to generate a sequence of random integers using Random() or RandomData(), but it needs to be repeatable any time the program is run... Obviously the solution is to use RandomSeed() with some desired seed to guarantee the same sequence each time!

But to save myself from any future bugs, I'm wondering if there is any possibility for RandomSeed() to give different results in a future version of PureBasic, OR in any of the current versions (4.60 in Mac, Linux, Windows 64-bit -- I currently use Win 32).

Perhaps I am safe, and a good algorithm was chosen 10 years ago, and Random/RandomSeed hasn't changed since?

But I know that some libraries are different across platforms (eg. the Packer algorithm?) and I want to be sure that a Mac or Linux port won't result in different random sequences.

Re: RandomSeed across versions and platforms

Posted: Fri Mar 09, 2012 4:39 am
by idle
If I remember PB uses the Mersenne twister prng, it's not likely to change
and it should produce the same results on all platforms from a given seed

Code: Select all

RandomSeed(1234)
Debug Random(1000)
;271 ubuntu 11.10 x86

Re: RandomSeed across versions and platforms

Posted: Fri Mar 09, 2012 7:54 am
by wilbert
I think the results are the same between different platforms
You can always use your own generator if you want to be absolutely sure.
I posted two a little while ago ( http://www.purebasic.fr/english/viewtop ... 12&t=49263 )
There are also simple ones with only a few lines of code. It depends what you need them for what works for you.

Re: RandomSeed across versions and platforms

Posted: Sun Mar 11, 2012 1:06 am
by kenmo
Thanks guys. It seems consistent across Linux and Windows x86 at least.

I have implemented what I needed using Random(), and when I port it to Mac / Win x64 later on I will double check it though.

If the PB team used a standard generator and implemented it themselves, I suppose there's no probable reason for it to be different across OS'es.

Re: RandomSeed across versions and platforms

Posted: Sun Mar 11, 2012 2:07 am
by freak
It produces the same output on all OS and processor types. The algorithm also didn't change in any PB version so far and I see no reason why it should in any future one.

The 64bit versions can use a 'Maximum' parameter in the quad range and the 32bit versions are limited to longs, but if you use a value in the long range the output will be identical on 32bit and 64bit.