17 Mar 2008 15:31
[Patch] use /dev/urandom for randomness if available
Jim Garrison <jim <at> garrison.cc>
2008-03-17 14:31:28 GMT
2008-03-17 14:31:28 GMT
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
-------------------------------------------------------------------------(Continue reading)

RSS Feed