diff --git a/core/lib/rand.h b/core/lib/rand.h index bc8344312..a543f0738 100644 --- a/core/lib/rand.h +++ b/core/lib/rand.h @@ -28,14 +28,16 @@ * * This file is part of the Contiki operating system. * - * @(#)$Id: rand.h,v 1.4 2007/09/04 08:48:54 bg- Exp $ + * @(#)$Id: rand.h,v 1.5 2009/02/11 11:09:59 adamdunkels Exp $ */ /* -*- C -*- */ -/* @(#)$Id: rand.h,v 1.4 2007/09/04 08:48:54 bg- Exp $ */ +/* @(#)$Id: rand.h,v 1.5 2009/02/11 11:09:59 adamdunkels Exp $ */ #ifndef RAND_H #define RAND_H +#include "sys/cc.h" + #undef RAND_MAX #define RAND_MAX 0x7fff diff --git a/core/lib/random.c b/core/lib/random.c index 814e7ba1b..8d48107b3 100644 --- a/core/lib/random.c +++ b/core/lib/random.c @@ -28,45 +28,24 @@ * * This file is part of the Contiki operating system. * - * @(#)$Id: random.c,v 1.2 2008/02/10 12:30:57 oliverschmidt Exp $ + * @(#)$Id: random.c,v 1.3 2009/02/11 11:09:59 adamdunkels Exp $ */ -/* - From: - - D. Seetharam and S. Rhee, ``An Efficient Random Number Generator - for Low-Power Sensor Networks'' First IEEE Workshop on Embedded - Networked Sensors (EmNets-I), November 2004. - - http://www.dseetharam.org/papers/emnets.pdf -*/ #include "lib/random.h" +#include "lib/rand.h" #include "sys/clock.h" -static clock_time_t time; - -static unsigned short key; - +/*---------------------------------------------------------------------------*/ void random_init(unsigned short seed) { - key = seed; + srand(seed); } - +/*---------------------------------------------------------------------------*/ unsigned short random_rand(void) { - unsigned short rv, tv; - - rv = tv = 0; - - tv = (unsigned short)(time + clock_time()); - rv = tv ^ key; - - key = ~tv + 4711; - tv = ~rv; - time = tv; - - return rv; + return (unsigned short)rand(); } +/*---------------------------------------------------------------------------*/