Loading random numbers into an array

Hi, Everyone!
Im trying to load random numbers into array, but not having much luck. Because i am seeding from time() in a While loop, the time has not changed by the time the loop exists. So, im getting an array with the same (or a very limited range) numbers. Here is the 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
29
30
31
32
33
34
#include <iostream>
using namespace std;


#include <time.h>
inline int ran()
{
	srand(time(0));
	return rand() % 100 + 1;
}

int main()
{

	int x = 0;

	int arr [100];

	while (x < 100)
	{
		arr[x] = ran();
		x++;
	}

	x = 0;

	while (x < 100)
	{
		cout << "\n" << arr[x];
		x++;
	}

	return 0;
}


Would someone mind looking at this and suggest an alternative way to either generate the numbers or loading the array?
srand() initializes the PRNG. time(0) returns the number of seconds since midnight, but since the computer can generate many numbers per second, it's very likely for each call to time(0) to return the same number, so rand() ends up always returning the same number.
To avoid this, call srand() just once at the beginning of the program.
GENUIS!!!
Makes perfect sense, now!

THANK YOU, Helios! Works a treat!!!
Topic archived. No new replies allowed.