lundi 29 mars 2021

Cpp random number with rand returns very similar numbers

I'm trying to generate a random number using rand() command, but each time i get very similar numbers. This is my code:

#include <iostream>
#include <time.h>
using namespace std;

int main()
{
    srand(time(0));
    cout << rand();
    return 0;
}

I ran it 5 times and the numbers i got are: 21767 21806 21836 21862 21888

How can i make the numbers be more different?




Aucun commentaire:

Enregistrer un commentaire