Fix ancient RAND_MAX compiler warning

This commit is contained in:
dak664 2010-12-13 16:52:02 +00:00
parent 3e293e6cfc
commit 9c66df6de1
3 changed files with 10 additions and 5 deletions

View file

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: random.c,v 1.4 2010/10/24 21:02:23 adamdunkels Exp $
* @(#)$Id: random.c,v 1.5 2010/12/13 16:52:02 dak664 Exp $
*/
@ -47,6 +47,9 @@ random_init(unsigned short seed)
unsigned short
random_rand(void)
{
/* In gcc int rand() uses RAND_MAX and long random() uses RANDOM_MAX=0x7FFFFFFF */
/* RAND_MAX varies depending on the architecture */
return (unsigned short)rand();
}
/*---------------------------------------------------------------------------*/

View file

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: random.h,v 1.1 2006/06/17 22:41:18 adamdunkels Exp $
* @(#)$Id: random.h,v 1.2 2010/12/13 16:52:02 dak664 Exp $
*/
#ifndef __RANDOM_H__
#define __RANDOM_H__
@ -46,6 +46,8 @@ void random_init(unsigned short seed);
*/
unsigned short random_rand(void);
#define RANDOM_MAX 65535U
/* In gcc int rand() uses RAND_MAX and long random() uses RANDOM_MAX */
/* Since random_rand casts to unsigned short, we'll use this maxmimum */
#define RANDOM_RAND_MAX 65535U
#endif /* __RANDOM_H__ */

View file

@ -32,7 +32,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: rpl-timers.c,v 1.13 2010/11/03 15:41:23 adamdunkels Exp $
* $Id: rpl-timers.c,v 1.14 2010/12/13 16:52:02 dak664 Exp $
*/
/**
* \file
@ -93,7 +93,7 @@ new_dio_interval(rpl_dag_t *dag)
/* random number between I/2 and I */
time = time >> 1;
time += (time * random_rand()) / RANDOM_MAX;
time += (time * random_rand()) / RANDOM_RAND_MAX;
dag->dio_next_delay -= time;
dag->dio_send = 1;