Problem with generation of casual numbers


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:


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.


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, ...).
Exactly! I try to use process identifier to generate different values.

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