jeudi 9 novembre 2017

generating a different random number every time a client runs

I am trying to code a client/server application in C where each client sends a specific value ( a randomly generated number between 1 to 50) to the server. But the problem is that each client sends the same random number to the server.

This is part of the code on the client side:

srand(time(NULL));
id=rand()%50 + 1; 

I do understand that since the seed is set to the same value each time a client runs and probably that's the reason why there is a same randum number as well. Can anyone please please suggest a way to rectify this ?

Thank you !




Aucun commentaire:

Enregistrer un commentaire