minor changes and documentation regarding using random generators in Cooja
This commit is contained in:
parent
cc56325300
commit
00273dce75
7 changed files with 373 additions and 334 deletions
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue