arrays, random number generators, and for loops

I am trying to use a random number generator (RNG) to fill in the array.
The array is 25 numbers long and i want the the random number generator to create the numbers and then using a FOR loop to fill in the arrays.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# include <iostream>
# include <cstdlib>
# include <ctime>
using namespace std;
int main ()

{
int a[25];
int i;
int b;
srand (( unsigned int ) time ( NULL ) );
for ( i = 0; i < 25; i++ )
{
cout << "Number is: " << rand ( ) % 100 << endl;
a[i] = rand() % 100;
}
for (i=0; i<25; i++)
cout << a[i] << endl;
return 0;
}


The problem i am having is the numbers in the array are not the same as the original numbers created by the RNG?
I list the original random numbers created in the first FOR loop then i try to list them again in the second FOR loop but they are not the same numbers?
How do i get the two FOR loops to produce the same numbers?
Thanks
Every time you call rand() you get a new random number.

You call it once on line 14.
Then again on line 15.

Hope this helps.
thanks!
that was great!
Topic archived. No new replies allowed.