Skip to main content
gamedev.net
🔒 Locked

Syncronized Random Numbers

Started by Sir Sapo Jan 30, 2006 at 4:16 PM 2 replies 1k views
Original Post
Sir Sapo
Sir Sapo
Hey everyone, I am seeding my random numbers with the current time, like so: srand(time(null)); In my multiplayer game, certain actions require a "roll of a dice", but I don't want to have to send the results of the "dice rolling"-function from client to client, I just want both clients to execute the code and get the same answer, which brings me to my question: If both the clients have had their random numbers seeded to the same time, and I execute a function on both clients, will the resulting random number be the same, or do I have to do something else to get them syncronized?
My Current Project Angels 22 (4E5)
rip-off
rip-off
Quote:
Original post by Sir Sapo
Hey everyone,

I am seeding my random numbers with the current time, like so:

srand(time(null));

In my multiplayer game, certain actions require a "roll of a dice", but I don't want to have to send the results of the "dice rolling"-function from client to client, I just want both clients to execute the code and get the same answer, which brings me to my question: If both the clients have had their random numbers seeded to the same time, and I execute a function on both clients, will the resulting random number be the same, or do I have to do something else to get them syncronized?


Don't depend on being able to execute the code at the same time. I would do it this way:

whatEverTimeReturns val = time(NULL);sendToClient( val );srand( val );
Sir Sapo
Sir Sapo
Damn, I didn't even consider that I would have to get both clients to execute the function at the same time. Is there another way to get the same results on two seperate machines, or should I just send the results of the number generation from one client to the other?
My Current Project Angels 22 (4E5)
Sneftel
Sneftel
Quote:
Original post by Sir Sapo
Damn, I didn't even consider that I would have to get both clients to execute the function at the same time. Is there another way to get the same results on two seperate machines, or should I just send the results of the number generation from one client to the other?

Even if you give them the same seed, they might use different random number generators. Use a custom-implemented RNG (look at boost::random for a few) and transmit the seed from one computer to the other.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.