minor changes and documentation regarding using random generators in Cooja

This commit is contained in:
fros4943 2009-02-18 12:07:19 +00:00
parent cc56325300
commit 00273dce75
7 changed files with 373 additions and 334 deletions

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: AreaViewer.java,v 1.4 2008/02/15 13:20:23 fros4943 Exp $
* $Id: AreaViewer.java,v 1.5 2009/02/18 12:08:10 fros4943 Exp $
*/
package se.sics.mrm;
@ -2128,7 +2128,7 @@ public class AreaViewer extends VisPlugin {
g2d.setTransform(realWorldTransformScaled);
g2d.setStroke(new BasicStroke((float) 0.0));
Random random = new Random();
Random random = new Random(); /* Do not use main random generator */
for (int i=0; i < trackedComponents.size(); i++) {
g2d.setColor(new Color(255, random.nextInt(255), random.nextInt(255), 255));
Line2D originalLine = trackedComponents.get(i);

File diff suppressed because it is too large Load Diff

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: MRM.java,v 1.7 2008/03/18 16:37:35 fros4943 Exp $
* $Id: MRM.java,v 1.8 2009/02/18 12:08:10 fros4943 Exp $
*/
package se.sics.mrm;
@ -63,7 +63,7 @@ public class MRM extends AbstractRadioMedium {
private ChannelModel currentChannelModel = null;
private Simulation mySimulation = null;
private Random random = new Random();
private Random random = null;
/**
* Notifies observers when this radio medium has changed settings.
@ -75,6 +75,7 @@ public class MRM extends AbstractRadioMedium {
*/
public MRM(Simulation simulation) {
super(simulation);
random = simulation.getRandomGenerator();
// Create the channel model
currentChannelModel = new ChannelModel();

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: SkyMote.java,v 1.10 2009/02/07 16:38:51 joxe Exp $
* $Id: SkyMote.java,v 1.11 2009/02/18 12:08:37 fros4943 Exp $
*/
package se.sics.cooja.mspmote;
@ -74,7 +74,7 @@ public class SkyMote extends MspMote {
// Add position interface
Position motePosition = new Position(this);
Random random = new Random();
Random random = new Random(); /* Do not use main random generator for positioning */
motePosition.setCoordinates(random.nextDouble()*100, random.nextDouble()*100, random.nextDouble()*100);
moteInterfaceHandler.addInterface(motePosition);

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: DummyVisualizer.java,v 1.1 2008/10/28 16:56:59 fros4943 Exp $
* $Id: DummyVisualizer.java,v 1.2 2009/02/18 12:07:42 fros4943 Exp $
*/
import java.awt.*;
@ -50,8 +50,6 @@ public class DummyVisualizer extends Visualizer2D {
private static final long serialVersionUID = 1L;
private static Logger logger = Logger.getLogger(DummyVisualizer.class);
private Random random = new Random();
public DummyVisualizer(Simulation simulationToVisualize, GUI gui) {
super(simulationToVisualize, gui);
setTitle("Dummy Visualizer");
@ -60,6 +58,7 @@ public class DummyVisualizer extends Visualizer2D {
}
public Color[] getColorOf(Mote m) {
Random random = new Random(); /* Do not use main random generator */
Color moteColors[] = new Color[2];
/* Outer color */
@ -76,6 +75,7 @@ public class DummyVisualizer extends Visualizer2D {
/* TODO Analyze data - determine color */
Random random = new Random(); /* Do not use main random generator */
return new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
}

View File

@ -26,10 +26,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: RandomIPDistributor.java,v 1.1 2006/08/21 12:13:06 fros4943 Exp $
* $Id: RandomIPDistributor.java,v 1.2 2009/02/18 12:07:19 fros4943 Exp $
*/
package se.sics.cooja.ipdistributors;
import java.util.Random;
import java.util.Vector;
import se.sics.cooja.*;
@ -42,16 +43,17 @@ import se.sics.cooja.*;
@ClassDescription("Random (10.10.?.?)")
public class RandomIPDistributor extends IPDistributor {
private Random random = new Random(); /* Do not use main random generator for setup */
/**
* Creates a random IP distributor.
* @param newMotes All motes which later will be assigned IP numbers.
*/
public RandomIPDistributor(Vector<Mote> newMotes) {
// NOP
}
public String getNextIPAddress() {
return "" + 10 + "." + 10 + "." + (Math.round(Math.random()*20) + 1) + "." + (Math.round(Math.random()*20) + 1);
return "" + 10 + "." + 10 + "." + (1+random.nextInt(20)) + "." + (1+random.nextInt(20));
}
}

View File

@ -26,10 +26,12 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: RandomPositioner.java,v 1.1 2006/08/21 12:13:11 fros4943 Exp $
* $Id: RandomPositioner.java,v 1.2 2009/02/18 12:07:19 fros4943 Exp $
*/
package se.sics.cooja.positioners;
import java.util.Random;
import se.sics.cooja.*;
/**
@ -41,6 +43,8 @@ import se.sics.cooja.*;
public class RandomPositioner extends Positioner {
double startX, endX, startY, endY, startZ, endZ;
private Random random = new Random(); /* Do not use main random generator for setup */
/**
* Creates a random positioner.
* @param totalNumberOfMotes Total number of motes
@ -65,9 +69,9 @@ public class RandomPositioner extends Positioner {
public double[] getNextPosition() {
return new double[] {
startX + Math.random()*(endX - startX),
startY + Math.random()*(endY - startY),
startZ + Math.random()*(endZ - startZ)
startX + random.nextDouble()*(endX - startX),
startY + random.nextDouble()*(endY - startY),
startZ + random.nextDouble()*(endZ - startZ)
};
}