It is currently Fri May 24, 2013 9:59 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: RandomSeed across versions and platforms
PostPosted: Fri Mar 09, 2012 2:38 am 
Offline
Addict
Addict
User avatar

Joined: Tue Dec 23, 2003 3:54 am
Posts: 932
Location: New York
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.


Top
 Profile  
 
 Post subject: Re: RandomSeed across versions and platforms
PostPosted: Fri Mar 09, 2012 4:39 am 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 2488
Location: New Zealand
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:
RandomSeed(1234)
Debug Random(1000)
;271 ubuntu 11.10 x86


Top
 Profile  
 
 Post subject: Re: RandomSeed across versions and platforms
PostPosted: Fri Mar 09, 2012 7:54 am 
Offline
Addict
Addict

Joined: Sun Aug 08, 2004 5:21 am
Posts: 1088
Location: Netherlands
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 ( viewtopic.php?f=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.


Top
 Profile  
 
 Post subject: Re: RandomSeed across versions and platforms
PostPosted: Sun Mar 11, 2012 1:06 am 
Offline
Addict
Addict
User avatar

Joined: Tue Dec 23, 2003 3:54 am
Posts: 932
Location: New York
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.


Top
 Profile  
 
 Post subject: Re: RandomSeed across versions and platforms
PostPosted: Sun Mar 11, 2012 2:07 am 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 5:21 pm
Posts: 5188
Location: Germany
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.

_________________
Perl – The only language that looks the same before and after RSA encryption.
-- Keith Bostic


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye