From 7f8ff9d9af824d1968185421909fd82aca212426 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Sat, 4 Nov 2017 17:55:31 +0100 Subject: [PATCH] Simulation script for tests with random rearrangement: use a random generator that lets us control the seed. Set the seed to the Cooja simulation seed. --- tests/14-rpl-lite/07-rpl-random-rearrangement.csc | 5 +++-- tests/15-rpl-classic/07-rpl-random-rearrangement.csc | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/14-rpl-lite/07-rpl-random-rearrangement.csc b/tests/14-rpl-lite/07-rpl-random-rearrangement.csc index cdb62c420..16ba26e20 100644 --- a/tests/14-rpl-lite/07-rpl-random-rearrangement.csc +++ b/tests/14-rpl-lite/07-rpl-random-rearrangement.csc @@ -544,7 +544,7 @@ make receiver-node.cooja TARGET=cooja } function getRandom(min, max) { - return Math.random() * (max - min) + min; + return r.nextFloat() * (max - min) + min; } // From: http://bost.ocks.org/mike/shuffle/ @@ -555,7 +555,7 @@ function shuffle(array) { while (m) { // Pick a remaining element… - i = Math.floor(Math.random() * m--); + i = Math.floor(r.nextFloat() * m--); // And swap it with the current element. t = array[m]; @@ -571,6 +571,7 @@ GENERATE_MSG(1200000, 'randomize-nodes'); GENERATE_MSG(2400000, 'randomize-nodes'); GENERATE_MSG(3600000, 'randomize-nodes'); +var r = new java.util.Random(sim.getRandomSeed()); var numForwarders = 20; var forwardIDStart = 4; packetsReceived = []; diff --git a/tests/15-rpl-classic/07-rpl-random-rearrangement.csc b/tests/15-rpl-classic/07-rpl-random-rearrangement.csc index cdb62c420..16ba26e20 100644 --- a/tests/15-rpl-classic/07-rpl-random-rearrangement.csc +++ b/tests/15-rpl-classic/07-rpl-random-rearrangement.csc @@ -544,7 +544,7 @@ make receiver-node.cooja TARGET=cooja } function getRandom(min, max) { - return Math.random() * (max - min) + min; + return r.nextFloat() * (max - min) + min; } // From: http://bost.ocks.org/mike/shuffle/ @@ -555,7 +555,7 @@ function shuffle(array) { while (m) { // Pick a remaining element… - i = Math.floor(Math.random() * m--); + i = Math.floor(r.nextFloat() * m--); // And swap it with the current element. t = array[m]; @@ -571,6 +571,7 @@ GENERATE_MSG(1200000, 'randomize-nodes'); GENERATE_MSG(2400000, 'randomize-nodes'); GENERATE_MSG(3600000, 'randomize-nodes'); +var r = new java.util.Random(sim.getRandomSeed()); var numForwarders = 20; var forwardIDStart = 4; packetsReceived = [];