[crossfire] server tests and random numbers
Mark Wedel
mwedel at sonic.net
Wed Sep 23 01:07:34 CDT 2009
The server has some number of tests that can be run if you have the necessary
dependencies and do a 'make check' to run them.
While many of the tests are always deterministic, some of them doing things
that are not deterministic - call treasure generation routines. The processing
of that uses the random number generator of the system.
If you're always on the same system, and seed the random number generator
correctly, the numbers are not really random. Right now, proper results are
given for linux systems. But I don't get the right results on solaris.
This can be illustrated pretty simply with this program:
main()
{
srandom(10);
printf("random is %d\n", random());
}
On solaris, I get:
random is 728127828
On linux (FC9 to be precise), I get:
random is 1215069295
I suspect some other operating systems may give different results, depending
on where there libc is derived (running on mac and windows would be interesting).
A simple fix, so the self tests pass, would be a simple check for those tests
that rely on random numbers to make sure it returns as expected (in this above
case, 1215069295), and if it doesn't just skip the test.
That isn't ideal, but at least easy to do. A comprehensive method might be to
have our own random number generator, at least as far as the tests go, that
gives deterministic results. I'm not sure if that is worth the effort or not.
More information about the crossfire
mailing list