need to improve random function

Hi guys,

So i am using this random function:

static int randomize(int pRango) {
int random;
srand(time(NULL));
random = rand() % pRango;
return random;
}

The problem is that i am calling it like every millisecond, i need random numbers to be shown on screen really quick. And basically i am getting this.

(if the argument is 5 for example) i get:

1
1
1
1
1
3
3
3
3
3
3
4
4
4
4
4
4
1
1
1
1

when i would actually like to receive more intercalation in the randomness, and get something like:
1
3
5
1
1
1
5

what can i change to achieve this?

thank you very much in advance.

JMA






Not reseeding the PRNG over and over again (with the same value, no less) might be a good start.
To elaborate.... srand should be called only once. You should not call it every time you call rand.
oh man! /facepalm!

THANK YOU GUYS! YOU ARE AWESOME.
Topic archived. No new replies allowed.