From eecb2c61836f3b1bce35ec105f23863b5a69b770 Mon Sep 17 00:00:00 2001 From: "Peter A. Bigot" Date: Mon, 17 Jun 2013 13:03:37 -0500 Subject: [PATCH] examples/trickle-library: correct probability expression Documented intent is to update with probability 1/NEW_TOKEN_PROB where NEW_TOKEN_PROB is 0x80. The current implementation updates with probability 1/2. Update NEW_TOKEN_PROB and the expression to keep existing behavior while correcting the calculation. Signed-off-by: Peter A. Bigot --- examples/trickle-library/trickle-library.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/trickle-library/trickle-library.c b/examples/trickle-library/trickle-library.c index 0cbc9a7ec..4f81cb39f 100644 --- a/examples/trickle-library/trickle-library.c +++ b/examples/trickle-library/trickle-library.c @@ -70,7 +70,7 @@ static uip_ipaddr_t ipaddr; /* destination: link-local all-nodes multicast * * with probability 1/NEW_TOKEN_PROB. This is controlled by etimer et. */ #define NEW_TOKEN_INTERVAL 10 * CLOCK_SECOND -#define NEW_TOKEN_PROB 0x80 +#define NEW_TOKEN_PROB 2 static uint8_t token; static struct etimer et; /* Used to periodically generate inconsistencies */ /*---------------------------------------------------------------------------*/ @@ -180,7 +180,7 @@ PROCESS_THREAD(trickle_protocol_process, ev, data) } else if(etimer_expired(&et)) { /* Periodically (and randomly) generate a new token. This will trigger * a trickle inconsistency */ - if((random_rand() & NEW_TOKEN_PROB) == 0) { + if((random_rand() % NEW_TOKEN_PROB) == 0) { token++; PRINTF("At %lu: Generating a new token 0x%02x\n", (unsigned long)clock_time(), token);