I do not know what within()
does, but you may want to use the new methods to generate random numbers introduced with C++11. The link has a nice example.
In case the link will become invalid in some future time, here’s the relevant code:
#include <iostream>
#include <random>
int main {
// Seed with a real random value, if available
std::random_device rd;
// Choose a random number between 1 and 6
std::default_random_engine engine(rd());
std::uniform_int_distribution<int> uniform_dist(1, 6);
int randomNumber = uniform_dist(engine);
int anotherRandomNumber = uniform_dist(engine);
std::cout << "Randomly-chosen number: " << randomNumber << '\n';
std::cout << "Another Randomly-chosen number: " << anotherRandomNumber << '\n';
}
0
solved why this function donnot generate random numbers? [closed]