+ 1
Random in c++
Is there a way to include random number generators in c++?
1 ответ
+ 6
Judging by your use case, srand() and rand() would suffice, where srand() seeds the RNG and rand() generates a random number.
https://www.sololearn.com/Discuss/151849/?ref=app
#include <iostream>
#include <cstdlib> // rand, srand
#include <ctime>
int main() {
srand(time(0));
std::cout << rand();
}
Ofc, if you want to venture even further, look into <random>.
https://en.cppreference.com/w/cpp/header/random