Jim Garrison | 17 Mar 2008 15:31

[Patch] use /dev/urandom for randomness if available

Hi!

For a game that is based on rolling dice, I found it surprising that
pioneers uses a pseudorandom sequence initialized with a call to
time(NULL).  If somebody knows roughly the time that a server process
began, as well as the results of the first few happenings of chance, it
is quite possible to determine the seed used and predict further
happenings of chance throughout the game.

At a minimum, I think the RNG's seed should be based on a less
predictable source of random data (/dev/urandom) if it is available.

The attached patch (made against svn) actually goes a step further, as
it uses /dev/urandom for all random numbers if it is available;
otherwise it falls back to glib's generator.

I started a new set of files (common/random.[c|h]) because it did not
make sense to me to have the random number routines in server/server.c
when they are used from common/map.c as well.  Feel free to put the GPL
notice in these files' headers, or feel free to move the function
wherever you see fit.

Any comments are appreciated.

All the best,
Jim
Attachment (pioneers-urandom.diff): text/x-diff, 5481 bytes
-------------------------------------------------------------------------
(Continue reading)

Roland Clobus | 10 Feb 2013 12:00
Face
Picon
Gravatar

Re: [pio-develop] [Patch] use /dev/urandom for randomness if available

Hello Jim and list,

On Mon, 2008-03-17 at 10:31 -0400, Jim Garrison wrote:
After nearly five years the reply follows... (blush)

> For a game that is based on rolling dice, I found it surprising that
> pioneers uses a pseudorandom sequence initialized with a call to
> time(NULL).  If somebody knows roughly the time that a server process
> began, as well as the results of the first few happenings of chance, it
> is quite possible to determine the seed used and predict further
> happenings of chance throughout the game.

At the moment you wrote the patch, it was very important for me to have
reproducible games (and it still is, see the game number as announced by
the server), because there were some problems with the computer player,
and I needed to be able to reproduce those games.

However, I fully agree that in a game based on rolling dice it should
not be easy to predict the upcoming dice rolls.
In the five years that have passed the glib library has included a
better random seeding mechanism based on /dev/urandom (which is recently
included in Pioneers, svn revision 1837).
The next upcoming release will therefore have a stronger randomisation
mechanism.

Thank you for noting the need for a better random seed,
Roland Clobus
------------------------------------------------------------------------------
(Continue reading)


Gmane