array with random function

Hey, guys, I got some problems with array function with random number on my code, please have some suggest. below is my code.

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
void smallarraymessage() 
{
	cout
		<<"      **************     SMALL array     **************      \n\n"
		<<"I am about to fully load smallArray with random generated numbers ... \n\n"
		<<"Finish loading smallArray ...                                 \n\n"
		<<endl;
}//

//int smallarray(int random)
//{


	int array[12] = {rand(),rand(),rand(),rand(),rand()};
	srand((unsigned)time(0));
	
	for (int i = 0; i < 12; i++)
	{
		array[i] = 1 + (rand() % 100);

       cout << "I am about to call printArray (with the default value for the perline)...   \n"
			<< setw(5) << rand() << endl;

	}system("pause");
	
	return 0;
}
What are this problems?

On thing: srand(...) shall be before any call to rand() because it seeds the random functionality. Thus it shall be called only once. The best would be at the top of main(...).
Topic archived. No new replies allowed.