+ 1
how does a rand() works?
#include <iostream> #include <cstdlib> using namespace std; int main() { for (int x = 1; x <= 10; x++) { cout << rand() << endl; } } every time how it's output can be same?
1 Resposta
+ 5
you'll need to use a seed like this: #include <ctime>
srand(time(nullptr));
so the current time is the seed for the rng now