[Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/tossim sim_tossim.c, 1.6, 1.7

Phil Levis scipio at users.sourceforge.net
Thu Oct 25 18:47:16 PDT 2007


Update of /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv14507

Modified Files:
	sim_tossim.c 
Log Message:
Fix zero-seed bug: the random number generator generates a stream of
zeroes if initialized with 0. Thanks to Konrad Iwanicki for the catch.


Index: sim_tossim.c
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/sim_tossim.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** sim_tossim.c	15 Jun 2007 00:45:18 -0000	1.6
--- sim_tossim.c	26 Oct 2007 01:47:12 -0000	1.7
***************
*** 56,60 ****
      struct timeval tv;
      gettimeofday(&tv, NULL);
!     sim_seed = tv.tv_usec;
    } 
  }
--- 56,70 ----
      struct timeval tv;
      gettimeofday(&tv, NULL);
!     // Need to make sure we don't pass zero to seed simulation.
!     // But in case some weird timing factor causes usec to always
!     // be zero, default to tv_sec. Note that the explicit
!     // seeding call also has a check for zero. Thanks to Konrad
!     // Iwanicki for finding this. -pal
!     if (tv.tv_usec != 0) {
!       sim_random_seed(tv.tv_usec);
!     }
!     else {
!       sim_random_seed(tv.tv_sec);
!     }
    } 
  }
***************
*** 83,86 ****
--- 93,100 ----
  
  void sim_random_seed(int seed) __attribute__ ((C, spontaneous)) {
+   // A seed of zero wedges on zero, so use 1 instead.
+   if (seed == 0) {
+     seed = 1;
+   }
    sim_seed = seed;
  }



More information about the Tinyos-2-commits mailing list