Need help with producing random numbers

Ok so i trying to create a random number generator, to generate random lotto numbers, but when i run the program i get the same number for all 5 here is the code i have so far:

//Random number generator for the lottery

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int regNum(int);

int main()
{
char answer;

cout<<" This a Random Lottery Number Generator \n Would you like to continue ? ";
cin>>answer;
if(answer=='Y' || answer=='y')
{
cout<<" Its good that you choose to continue. \n Here are your Regular Numbers";
//displays 5 random numbers for user to apply to lottery
for( int i=0;i<5;i++)
{
cout<<regNum(time(0))<<" ";

}



}else cout<<"Have a good day \n Press Enter to exit.\n \n";
exit(1);
return 0;
}

int regNum(int num )
{
int regNUM;
srand(num);
regNUM=(rand()%56)+1;
return regNUM;
}

can anyone show me the way to 5 different numbers.
Last edited on
Just call srand once at the beginning of main.

try this approach and got errors.
what kind of errors?
it goes to the Header file
You are obviously doing something wrong.
why yes i am, a guiding light would be helpful
Here is your code with the change I was talking about
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//Random number generator for the lottery

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int regNum();

int main()
{
	srand(time(0));
	char answer;

	cout<<" This a Random Lottery Number Generator \n Would you like to continue ? ";
	cin>>answer;
	if(answer=='Y' || answer=='y')
	{
		cout<<" Its good that you choose to continue. \n Here are your Regular Numbers";
		//displays 5 random numbers for user to apply to lottery
		for( int i=0;i<5;i++)
		{
			cout<<regNum()<<" ";
		}
	}
	else 
	{
		cout<<"Have a good day \n Press Enter to exit.\n \n";
	}
	exit(1);
	return 0;
}

int regNum()
{
	int regNUM;
	regNUM=(rand()%56)+1;
	return regNUM;
}

I just learned how to do that a couple of hours ago.
The code is pretty much the same that peter87 wrote.
But if you would like for it to be explained in a video I wil ref you to where i learned it.
There's some very good tuts for beginners like me.

http://thenewboston.org/watch.php?cat=16&number=27
Last edited on
aww man thanks peter that was good stuff i was under the impression you have to pass something to function definition from the function call. now i know better
Topic archived. No new replies allowed.