I have an app that will display Lotto Max numbers, I need to make my app generate random numbers but I need the numbers to not repeat. I have my code done and would like to change a little as possible. But any help would be awesome!
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
int main()
{
{
cout << "*** LOTTO MAX INSTA PICK ***" << endl;
cout<< " " << endl << endl;
}
{
cout << "Your Insta Pick Numbers" << endl;
cout<< " " << endl << endl;
}
for (int counter = 1; counter <= 21; ++ counter)
{
cout << setw(1) << (1 + rand() % 49) << " ";
if (counter % 7 == 0)
cout << endl;
}
{
cout<< " " << endl << endl;
}
{
cout << "Your Tag Numbers" << endl;
cout<< " " << endl << endl;
}
for (int counter = 1; counter <= 9; ++ counter)
{
cout << setw(1) << (0 + rand() % 9)<< " ";
if (counter % 9 == 0)
cout << endl;
}
{
cout<< " " << endl << endl;
}
{
cout << "Thank you for playing!! please check ticket\n a year minus a day from date of purchase" <<endl;
}
};
Before using the
randfunction, you need to seed the generator with a unique value. This is done with thesrandfunctions. Commonly the unique number is the current time as returned bytime:Unless you manage to run the application several times in a single second, the result will be unique every time you run the application.