[Tinyos-devel] Random numbers in TOSSIM

Philip Levis pal at cs.stanford.edu
Thu Oct 25 18:48:29 PDT 2007


On Oct 13, 2007, at 7:51 AM, Konrad Iwanicki wrote:

> Hello Phil,
>
> On Fri, 12 Oct 2007, Philip Levis wrote:
>
>> On Oct 11, 2007, at 5:29 AM, Konrad Iwanicki wrote:
>>
>>> Hi all,
>>>
>>> TOSSIM has some drawbacks regarding random seed initialization.
>>>
>>> 1. It may happen that the seed is set to 0. As a result, all  
>>> randomly
>>> generated numbers are 0. This situation occurred a number of times
>>> when
>>> I was extensively testing of my algorithms with TOSSIM, so it is not
>>> unlikely to happen.
>>>
>>> 2. It is virtually impossible to repeat experiments with the same
>>> random
>>> seed without modifying TOSSIM.
>>>
>>> For these reasons, I made some small changes to the sim_init()
>>> function
>>> in the sim_tossim.c file (see below). Essentially, one can  
>>> redefine a
>>> macro, TOSSIM_RANDOM_SEED, at compile time to set his/her own  
>>> seed. In
>>> addition, the code prevents the seed from being equal to 0.
>>>
>>> **Can somebody integrate these changes with the sourceforge CVS
>>> tree**?
>>
>> Why does Tossim::randomSeed(int seed) not work?
>
> Yes, true it works in the second case (my mistake). However, my point
> was rather, apart from the TOSSIM_RANDOM_SEED macro, providing a  
> mechanism
> that ensures that the seed is non-zero by default, and thus, the
> modifications to sim_init.

I checked in a modification of your fix, that feeds tv_sec if tv_usec  
is zero but also uses 1 if the seed itself is zero (e.g., a mistake  
by a user). Thanks for the catch!

Phil


More information about the Tinyos-devel mailing list