samedi 4 septembre 2021

srand() is not working when used with parameter

i've got a problem with srand(), it works only when I fill parameter with number, for example srand(1234), but when I try to use it with 'n' or with time (as below), then randint keeps returning the same seed.

#include <iostream>
#include <algorithm>
#include <experimental/random>
#include <cstdlib>
#include <ctime>

using namespace std;

int main() {
    srand(time(nullptr));
    for (int i = 0; i < 4; ++i) {
        int random = experimental::randint(0, 9);
        cout << random;
    }
}

Thanks for your time.




Aucun commentaire:

Enregistrer un commentaire