Problem with generation of casual numbers

Hi,

I have a project with five clients that must to generate casual numbers between 0 and 19 and then send them to server.
Problem is that in every execution the mains generates same values:

Example:

Main 0 : 2 0 3 15 9....
Main 1 : 2 0 3 15 9....
Main 2 : 2 0 3 15 9....

and so on, i want different numbers by each execution.
Under i report my code used to generate casual numbers, which would be the problem?

Thanks to all.

1
2
3
4
#include<time.h>

srand((unsigned)time(NULL));
int choice = rand()%20;
Last edited on
You probably run all the clients around the same time, in the same second. So they'll all be seeded with the same value.

Try seeding with the process id (or time + process id, ...).
http://www.freebsd.org/cgi/man.cgi?query=getpid&apropos=0&sektion=0&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html
Exactly! I try to use process identifier to generate different values.

Thanks a lot!
Topic archived. No new replies allowed.