So i made this function in a header file and i'm calling it from main.cpp, but it seems like all it does is just count infinitely, even though i put %1000+1. It's in the 10000s now and nothing seems to make it return a number from 1 to 1000.
UsefulFunctions.h :
#ifndef USEFULFUNCTIONS_H
#define USEFULFUNCTIONS_H
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int generateRandomNr()
{
srand((unsigned)time(0));
int x = (rand()%1000)+1;
return (int)x;
}
#endif // USEFULFUNCTIONS_H
main.cpp :
#include <iostream>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "UsefulFunctions.h"
using namespace std;
int main()
{
cout << generateRandomNr();
return 0;
}
I've tried changing values, just returning rand()%1000+1, rebuilding the project, but nothing worked. It just kept counting and i keep getting results like : 16380 16425 16484 16527
Please help.