hi
My random number function is meant to loop 6 times & output 6 different numbers. But instead it outputs 6 of the same numbers. How do I fix it? :)
Any advice would be really helpful.
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <string>
using namespace std;
int random(int max)
{
srand(time(NULL));
return ((rand()%max)+1);
}
int main()
{
for (int i=0; i<6; i++) {
used_nos[i] = random(40);
cout << used_nos[i] << endl;
}
return 0;
}