Jump to content
  • Advertisement
Sign in to follow this  
ed209

networking question concerning random numbers

This topic is 3734 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I just created a pong game that uses random numbers to calculate where the ball is travelling. Problem is is that when I have a server and a client, they will have two different random numbers. Whats the ebst way to have it so that they both the server and the client generate the same random numbers?

Share this post


Link to post
Share on other sites
Advertisement
Thats what I was doing, but my goal is to make a nes emulator with multiplayer support. Are you telling me that I would have to do this with every randomly generated number if I was to make the emulator???

Share this post


Link to post
Share on other sites
With PRNG you can just sends seeds during handshake. As long as you maintain perfect synchronization, the "random" numbers will generate exactly the same sequences on both computers.

This type of networking was documented on gamasutra. It's tricky, but definitely doable.

Share this post


Link to post
Share on other sites
Quote:
Original post by Antheus
With PRNG you can just sends seeds during handshake. As long as you maintain perfect synchronization, the "random" numbers will generate exactly the same sequences on both computers.
This really is the magic bullet for solving random number synch issues in any instance in which client knowledge of the number gen doesn't pose a large security risk. You can actually relax the constraint of perfect synchronization somewhat if you institute an absolute ordering of events within certain code regions rather than within the system as a whole. This would allow you a bit more flexibility with respect to your network events interacting with non-networked events [like, for example, one number gen running for things that originate client side, and another one for network messages. Thus the nondeterminism of network traffic doesn't force you to roll back previous moves that are the product of locally relevant numbers].

Share this post


Link to post
Share on other sites
So as long as the game never comes out of synch, I can generate two random numbers?

Share this post


Link to post
Share on other sites
Quote:
Original post by ed209
So as long as the game never comes out of synch, I can generate two random numbers?


Only if the pseudorandom number generators are given the same seed. So the server would send the seed to the clients, which would then seed their PRNGs with it - the result being that every n-th call for a random number would result in the same random number across the clients.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!