From 13a3029435b77ed61dc60ad4c7efd6965d634696 Mon Sep 17 00:00:00 2001 From: adamdunkels Date: Wed, 11 Feb 2009 11:09:59 +0000 Subject: [PATCH] Rewrote the random_rand() pseudo random number generator to use the libc rand() function instead --- core/lib/rand.h | 6 ++++-- core/lib/random.c | 35 +++++++---------------------------- 2 files changed, 11 insertions(+), 30 deletions(-) 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(); } +/*---------------------------------------------------------------------------*/