I am trying to generate 30 random integer numbers between 0 and 4, so I've used a for loop. The problem is that it generates the same random variable (say 3), while I'm using time(0) to get a new seed in every iteration.
#include <iostream>
#include <cstdlib>
#include "time.h"
using namespace std;
int main()
{
for (int number=0;number<30;number++)
{
srand(time(0));
int randomNumber = rand()%5;
cout << randomNumber << endl;
}
}
Aucun commentaire:
Enregistrer un commentaire