So I have a program to make random numbers using a vector and technically it s working but every time I run the program it gives me numbers like, 22 22 34 34 34 34 34 or 13 13 30 30 30 30 30. So it gives me different numbers each time but not really. Any help on getting completely random numbers each time.
#include <iostream>
#include <random>
#include <algorithm>
#include <cstdlib>
#include <time.h>
#include <vector>
using namespace std;
void regular();
void bonus();
int main() {
regular();
//bonus();
}
void regular() {
cout << "These are your regular numbers." << endl;
int i = 0;
vector<int> regs;
srand(time(NULL));
for (i = 0; i < 7; i++) {
int x = rand() % 39 + 1;
regs.push_back(x);
sort(regs.begin(), regs.end());
cout << regs[i] << " ";
}
cout << endl;
}
void bonus() {
cout << "These are your bonus numbers." << endl;
int i = 0;
srand(time(0));
for (i = 0; i < 7; i++) {
cout << rand() % 39 + 1 << "";
}
}
Aucun commentaire:
Enregistrer un commentaire