Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Inconsistent seeds for different operating systems [DISP  (Read 922 times)

Lord Nightmare

  • Bay Watcher
    • View Profile
Inconsistent seeds for different operating systems [DISP
« on: December 05, 2007, 10:43:00 pm »

EDIT: This is not true. I went ahead and tested it (which I really should have done in the first place. Silly me, trusting other people's words...), win2k and winXP generate identical worlds, even for 'problem' worlds like paul's world, seed 4265985437.
A report posted in the DF general forums claimed that paul's world seed produced similar but non-identical worlds. This seems to have been caused by anonymousphrase modding his raws somehow and is not a problem with DF at all.
Paul's screenshot, which is what XP and 2K both match: http://img222.imageshack.us/img222/7413/location2in8.png
anonymousphrase's screenshot, ostensibly created with raws which were modified somehow: http://i21.tinypic.com/2mgjjft.png

So all in all, this 'bug' seems to not exist, at least between windows 2k IA32 and windows XP IA32. It MIGHT still exist with 64 bit versions of either, but someone else has to test that.

LN


Old, disproved report follows, ignore it.

The random number generation system used on windows XP and Vista is not exactly the same as the one used on windows 2000, and since df uses the random generation calls directly, fortress seeds produce different results on different operating systems. DF should have an internal random number generator which is identical to the one XP and Vista use.
Edit: actually, the difference is between the implementations of MSVCRT rand()
the windows XP implementation is, I BELIEVE (someone with msvc please test this):
#define RAND_MAX MSVC_rand_max
/* globals */
int32 oldseed = 0; /* 32 bit value, signed */
uint32 MSVC_rand_max = 0x7fff; /*<- usually defined using RAND_MAX somewhere in code, defaults to 0x7fff otherwise */

int32 MSVC_rand(void) /* returns a random number between 0 and RAND_MAX */
{
   int32 newseed;
   newseed = ((oldseed * 214013) + 2531011) % 2147483648;
   oldseed = newseed;
   return (newseed >> 16) & MSVC_rand_max;
}

void MSVC_srand(int newseed)
{
   oldseed = newseed;
}

(Somewhat unrelated, the Windows 2000 'CryptGenRandom' random number generator meant for cryptography, (which i do NOT think is the one DF uses) was reverse engineered by some Israeli researchers, and the code is described here: http://eprint.iacr.org/2007/419.pdf
)

LN


P.S. One more important thing: every program thread has its own copy of the 'oldseed' variable, so if multiple threads call rand() it will behave as expected WITHIN EACH THREAD but not globally.

[ December 06, 2007: Message edited by: Lord Nightmare ]

[ December 06, 2007: Message edited by: Lord Nightmare ]

[ December 09, 2007: Message edited by: Lord Nightmare ]

Logged
"When life gives you zombies... *CHA-CHIK!* ...you make zombie-ade!"

PTTG??

  • Bay Watcher
  • Kringrus! Babak crulurg tingra!
    • View Profile
    • http://www.nowherepublishing.com
Re: Inconsistent seeds for different operating systems [DISP
« Reply #1 on: December 05, 2007, 11:07:00 pm »

OR! we could use the live random particle motion feed, so DF, when connected to the internet, will be PERFECTLY random. Like [insert party here] politics!
Logged
A thousand million pool balls made from precious metals, covered in beef stock.

sphr

  • Bay Watcher
    • View Profile
Re: Inconsistent seeds for different operating systems [DISP
« Reply #2 on: December 06, 2007, 12:04:00 am »

For a platform indepedent solution, consider Random Number Library from Boost Libraries. It has both deterministic and ND random number generators.

Lord Nightmare

  • Bay Watcher
    • View Profile
Re: Inconsistent seeds for different operating systems [DISP
« Reply #3 on: December 06, 2007, 12:09:00 am »

not gonna work. if the rand() algorithm is CHANGED then the existing world seeds will no longer work. I'm trying to avoid that.

LN

Logged
"When life gives you zombies... *CHA-CHIK!* ...you make zombie-ade!"

Core Xii

  • Bay Watcher
    • View Profile
Re: Inconsistent seeds for different operating systems [DISP
« Reply #4 on: December 06, 2007, 04:07:00 am »

I thought DF used the mersenne twister.
Logged
Reality is for people who lack imagination

sphr

  • Bay Watcher
    • View Profile
Re: Inconsistent seeds for different operating systems [DISP
« Reply #5 on: December 06, 2007, 04:43:00 am »

quote:
Originally posted by Lord Nightmare:
<STRONG>not gonna work. if the rand() algorithm is CHANGED then the existing world seeds will no longer work. I'm trying to avoid that.

LN</STRONG>


What I mean is: if we know what the type of RNG is originally being used, perhaps we can ask Toady to replace the call to system's rand() with a call to the explicitly specified RNG.

e.g. if the original worlds were built on a system using mersenne twister, then if the random number part is made portable, the binary should generate the exact same random number seq on the same seed regardless of plaform/OS from then on.  Boost Random Number just seems like a nice alternative as it provides all the basic deterministic RNG without having to code/debug it ourselves.

Lord Nightmare

  • Bay Watcher
    • View Profile
Re: Inconsistent seeds for different operating systems [DISP
« Reply #6 on: December 07, 2007, 02:06:00 am »

sphr: thats EXACTLY what I was saying! the code in my first post SHOULD be identical to the rand() and srand() calls in msvc in win xp, and can be incorporated in the program code itself to do random number generation in a platform independent way which still works for all existing seeds (which were generated in winXP).
An init.txt option to select between the winxp and win2k rand() functions would be nice, but I don't know the equations for the latter.

LN

Logged
"When life gives you zombies... *CHA-CHIK!* ...you make zombie-ade!"

Toady One

  • The Great
    • View Profile
    • http://www.bay12games.com
Re: Inconsistent seeds for different operating systems [DISP
« Reply #7 on: December 07, 2007, 02:03:00 pm »

I am using a Mersenne twister.  My few calls to rand/srand/the timer occur right before the in-play action starts, when I wanted things to be randomized (after each load for example).  If there are differences between world maps between operating systems, it's a bug of some kind, but it shouldn't be related to rand/the timer.  Are there any screenshots of this problem with OS/seed labels?  I've heard people talk about it but I haven't seen anything, so I'm not even sure which aspect of the game is being talked about.
Logged
The Toad, a Natural Resource:  Preserve yours today!

Lord Nightmare

  • Bay Watcher
    • View Profile
Re: Inconsistent seeds for different operating systems [DISP
« Reply #8 on: December 09, 2007, 03:05:00 am »

Disproved, in the case of WinXP and Win2k. Someone else will have to test a vanilla install and WINE in linux but I suspect it works fine there too.

LN

Logged
"When life gives you zombies... *CHA-CHIK!* ...you make zombie-ade!"

Griz

  • Bay Watcher
    • View Profile
Re: Inconsistent seeds for different operating systems [DISP
« Reply #9 on: December 09, 2007, 04:07:00 am »

quote:
Originally posted by Toady One:
<STRONG>Are there any screenshots of this problem with OS/seed labels?  I've heard people talk about it but I haven't seen anything, so I'm not even sure which aspect of the game is being talked about.</STRONG>

more screenshots of seed 4265985437

what I got in XP SP2: http://i21.tinypic.com/2nlfu5i.jpg
what anonymousphrase got (I assume he's running some form of Linux since he posted in a DF Linux thread): http://i20.tinypic.com/209q8tu.png

more discussion in this thread http://www.bay12games.com/cgi-local/ultimatebb.cgi?ubb=get_topic&f=2&t=001247&p=2

the shape of the terrain is exactly the same, but he got a different color sand, and the magma is in a different place.

[ December 09, 2007: Message edited by: Griz ]

Logged

Lord Nightmare

  • Bay Watcher
    • View Profile
Re: Inconsistent seeds for different operating systems [DISP
« Reply #10 on: December 09, 2007, 10:28:00 am »

In WinXP the embarked map matches what you see...
(win2k test coming in a bit)

LN

Logged
"When life gives you zombies... *CHA-CHIK!* ...you make zombie-ade!"