I'm just starting out, trying to learn to program. So I'm programming in C++ for now, and I tried to create a function that will generate a random vector of integers based on the parameters. So my function so far looks like this:
std::vector<int> GenerateRandomVector(int NumberCount,int minimum, int maximum) {
std::vector<int> vecRandomValues;
int i = 0, randValue = 0;
srand(time(NULL));
while (i < NumberCount) {
randValue = rand() % maximum + minimum;
vecRandomValues.push_back(randValue);
i++;
}
return vecRandomValues;
}
So, my problem is that it does not respect the minimum and maximum value I give it, and also most of the time, 40% of the generated numbers are 0. I cannot figure out what I did so wrong here, nor do I have any idea on how to fix it. I'm using Clion on Windows 10.
Aucun commentaire:
Enregistrer un commentaire