#ifndef REQUESTGENERATOR_H_
#define REQUESTGENERATOR_H_
#include <iomanip>
#include <iostream>
using namespace std;
class requestGenerator {
public:
int randomStar = 0;
int amountOfEvents = 0;
int randomEventArray[10];
int possibleEventArray[15] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
void generator() {
while (randomStar <= 2) {
randomStar = rand() % 5;
}
cout << randomStar << endl;
while (amountOfEvents == 0) {
amountOfEvents = rand() % 10;
}
cout << amountOfEvents << endl;
for (int i = 0; i != amountOfEvents; i++) {
bool numberGened = false;
while (numberGened = false) {
randomEventArray[i] = rand() % 15;
if (possibleEventArray[i] != -1) {
numberGened = true;
possibleEventArray[i] = -1;
}
}
cout << randomEventArray[i] << " ";
}
}
};
#endif /*REQUESTGENERATOR_H_ */
When it outputs the generated number it gives -858993460 nine times. I am not sure why. 'possibleEventArray' is meant to hold all possible values. While the generated number goes into randomEventArray
possibleEventArray[ rand()%15 ]instead ofpossibleEventArray[ i]. Further, it seems like you want to generate a random permutation of the elements inpossibleEventArray. For this there are duplicates aroundif (possibleEventArray[i] != -1)will betruealways