[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ESPResSo-users] IMPORTANT: Seeding Random Numbers & ESPResSo!!!

From: Joost de Graaf
Subject: [ESPResSo-users] IMPORTANT: Seeding Random Numbers & ESPResSo!!!
Date: Wed, 27 Mar 2013 20:48:15 +0100

Dear All,

BE WARNED: the following may (have) influence(d) your results as well!
There is a problem with the "t_random seed" tcl function in ESPResSo,
if you use clock clicks times pid or some other long number as your
seed. When a seed (e.g. s0) is passed

t_random seed s0

The seed s0 gets cast from a string to a long int using the stdlib
"atol" function. The description of the atol function reads:

"If str does not point to a valid C-string, or if the converted value
would be out of the range of values representable by an long int, it
causes undefined behavior"

Said undefined behaviour can occur when you put

t_random seed [expr [clock clicks]*[pid]]

for instance, since that's typically quite a long number. Depending on
your architecture, this could mean that your random number generator
is initialized with the same seed every run and you can get highly
correlated data! I'll put an entry into the User's Guide for the next
release. You could still use clock clicks times pid or some other
large number, provided you ensure that you stay within the bounds of
the long int format yourself on the Tcl level, say:

t_random seed [expr [clock clicks]*[pid]%2147483647]

would probably work on most architectures, but be careful with this.

Kind Regards,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]