First, I have Arraylist "listVertex" storing "coordinates" of DTNHost. Second, I created a method to get random elements for the selected index from listVertex ArrayList. However, the following methods generate new coordinate points and the values x and y change from the initial value I have specified. Please guys, help me to get random elements from theVertex list without having to generate new coordinate points and the value x, y does not change. Thanks for the attention.
//retrieve node coordinates from DTNHost.
public void getVertex() {
List<DTNHost> allNode = SimScenario.getInstance().getHosts();
for (DTNHost host : allNode) {
if (host.toString().startsWith("kota")) {
listVertex.add(host.getLocation());
}
}
}
//get for random elements from the listVertex ArrayList
public ArrayList<Coord> randomVeretx(int max) {
Random r = new Random();
ArrayList<Coord> result = new ArrayList<Coord>();
for (int i = 0; i < max; i++) {
result.add(new Coord(r.nextDouble() * max, r.nextDouble() * max));
}
return result;
}
Aucun commentaire:
Enregistrer un commentaire