C ++ for selecting two random numbers from a range with minimum distance
I have a std :: vector initialized with numbers from 1 to 100
std::vector<int> vec;
for(int i = 1; i < 101; i++)
vec.push_back(i);
I want to select two random numbers that have a minimum distance (for example, the minimum distance might be 10).
If num1, num2 are numbers:
num2 - num1> distance
I am using the following method to select a random integer between ranges:
int getRandomValue(int from, int to)
{
std::random_device seeder;
std::mt19937 engine(seeder());
std::uniform_int_distribution<int> dist(from, to);
return dist(engine);
}
How can I generate num2 and num1?
+3
source to share
3 answers