I want to understand how it is better to get random numbers, for example, for some kind of game. On this occasion, I ask for your help. So that I can imagine myself well, please explain to me with a simple example what is better and why.
class Random_numbers { int m, s; public: Random_numbers(int max, int start = 0) : m(max + 1), s(start) {} int operator ()() { return rand() % m + s; } }; int main() { const int N = 20, r = 100; std::vector<int> v(2 * r); auto f = v.begin(), end = v.end(); std::generate(f, end, []() { static int n = -100; return ++n;}); std::random_shuffle(f,end); std::copy_n(f, N, ostream_iterator<int>(std::cout, " ")); std::cout << std::endl << std::endl; // второй способ Random_numbers Rn(2 * r, -100); int number = 0; srand(time(0)); for (int i = 0; i < N; ++i) { number = Rn(); std:: cout << number <<' '; } return 0; } What is the difference between these 2 ways and which way will give the result preferable and why? If there are a lot of questions, I’ll be satisfied with the answer only to the first question.
rand(). - Harry