Reputation: 11
I am new to Cooja simulation. I am using the mobility plugin to make my motes move around. but It works for 15 nodes at most. Is there any way to move more nodes like 200 motes in the simulation?
Upvotes: -1
Views: 116
Reputation: 11
I found the solution. The only thing is to change the number of nodes in the following code:
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <set>
// Function to generate two random numbers between 35 and 150 with 6 decimal digits
std::pair<double, double> random_numbers(std::set<double>& used_nums) {
// Seed the random number generator
std::srand(std::time(nullptr));
// Generate two random doubles between 35 and 150
double rand_double1 = (static_cast<double>(std::rand()) / RAND_MAX) * 115.0 + 35.0;
double rand_double2 = (static_cast<double>(std::rand()) / RAND_MAX) * 115.0 + 35.0;
// Check if the random numbers are already in the set
while (used_nums.count(rand_double1) || used_nums.count(rand_double2)) {
rand_double1 = (static_cast<double>(std::rand()) / RAND_MAX) * 115.0 + 35.0;
rand_double2 = (static_cast<double>(std::rand()) / RAND_MAX) * 115.0 + 35.0;
}
// Add the random numbers to the set
used_nums.insert(rand_double1);
used_nums.insert(rand_double2);
return std::make_pair(rand_double1, rand_double2);
}
int main() {
// First loop
for (float i = 0; i <= 599.8; i+= 0.2) {
// Second loop
std::set<double> used_nums; // declare the set here
for (int j = 0; j <= 3000; j ++) {
std::pair<double, double> rand_nums = random_numbers(used_nums);
double rand_num1 = rand_nums.first;
double rand_num2 = rand_nums.second;
std::cout << j << " " << i <<" "<< rand_num1 << " " << rand_num2 << "\n";
}
}
return 0;
}
Upvotes: 0