From fbb09061c862c727f01a5621d19fdae17ee150b0 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Wed, 18 Feb 2009 10:41:50 +0000 Subject: [PATCH] example mote implementation uses main random generator --- .../java/se/sics/cooja/motes/DummyMote.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/motes/DummyMote.java b/tools/cooja/java/se/sics/cooja/motes/DummyMote.java index fbbe2a0cb..2eb2e4d05 100644 --- a/tools/cooja/java/se/sics/cooja/motes/DummyMote.java +++ b/tools/cooja/java/se/sics/cooja/motes/DummyMote.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: DummyMote.java,v 1.6 2008/12/04 14:03:42 joxe Exp $ + * $Id: DummyMote.java,v 1.7 2009/02/18 10:41:50 fros4943 Exp $ */ package se.sics.cooja.motes; @@ -68,7 +68,7 @@ public class DummyMote implements Mote { private MoteInterfaceHandler myInterfaceHandler = null; private Simulation mySim = null; - private Random myRandom = new Random(); + private Random random = null; /** * Creates a new uninitialized dummy mote. @@ -88,6 +88,7 @@ public class DummyMote implements Mote { public DummyMote(MoteType moteType, Simulation sim) { mySim = sim; myType = moteType; + random = mySim.getRandomGenerator(); // Create memory myMemory = new SectionMoteMemory(new Properties()); @@ -95,8 +96,11 @@ public class DummyMote implements Mote { // Create interface handler myInterfaceHandler = new MoteInterfaceHandler(); Position myPosition = new Position(this); - myPosition.setCoordinates(myRandom.nextDouble() * 100, myRandom - .nextDouble() * 100, myRandom.nextDouble() * 100); + myPosition.setCoordinates( + random.nextDouble() * 100, + random.nextDouble() * 100, + random.nextDouble() * 100 + ); myInterfaceHandler.addInterface(myPosition); } @@ -149,13 +153,13 @@ public class DummyMote implements Mote { public boolean tick(long simTime) { // Perform some dummy task - if (myRandom.nextDouble() > 0.9) { + if (random.nextDouble() > 0.9) { // Move mote randomly Position myPosition = myInterfaceHandler.getPosition(); myPosition.setCoordinates(myPosition.getXCoordinate() - + myRandom.nextDouble() - 0.5, myPosition.getYCoordinate() - + myRandom.nextDouble() - 0.5, myPosition.getZCoordinate() - + myRandom.nextDouble() - 0.5); + + random.nextDouble() - 0.5, myPosition.getYCoordinate() + + random.nextDouble() - 0.5, myPosition.getZCoordinate() + + random.nextDouble() - 0.5); } return false; } @@ -187,6 +191,7 @@ public class DummyMote implements Mote { Collection configXML, boolean visAvailable) { mySim = simulation; myMemory = new SectionMoteMemory(new Properties()); + random = mySim.getRandomGenerator(); myInterfaceHandler = new MoteInterfaceHandler(); myInterfaceHandler.addInterface(new Position(this));