I'm building a realtime multiplayer game that runs the same 'physics' loop on client and server. I'm using a steering behavior 'wander' that is essential random movement. The client and server generate different Random numbers when running the wander algorithms.

I'm wondering how I can keep a naturally random looking movement but use some constant that will insure the client and server come to the same conclusion.

  • 4
    \$\begingroup\$ Generating the same random sequence from a pseudo random number sequence is easy. The hard thing is synchronizing the use of that sequence. You need to make your game logic deterministic, not in the sense that you're not using a random sequence, but to use the random sequence in a deterministic way. The easiest way to achieve this is usually to avoid any concurrency in the game logic loop, however it is possible to have concurrency as long as the threads do not depend on the timing and sequencing of the PRNG when asking the PRNG for a random value. Here be dragon. \$\endgroup\$
    – Lie Ryan
    Dec 8, 2014 at 4:47

2 Answers 2


You can use random seed. Select same 32-bit value in server and client (or server can send it to client at start). Use it as seed for random generator. You can send actual seed from server to client with game state update. If you don't want to send it you must be sure that client and server generates same number of random numbers by this random generator.

What you should know before you decided not send actual seed to client:

  • You'll have problems with character culling on client (means don't process characters deep in a fog of war on client). If you want to make character culling best decision will be send all character state (with actual seed) from server to client when client should process character. So, server must decide when client should process character and when shouldn't. Be sure that you use separate random generators for each character.
  • Same problem will be with AI lods.
  • Random number from this random generator must be generated only in update with fixed time delta. If you want to use random digit for AI interpolation before render you should use separate random generator (there are no render on server, so don't care what seed you'll use).
  • If you want to use different platforms for client and server (C++ and Java, for example), you must implement (or find) crossplatform random generator. That's not a big problem, because random generators easy to implement.

If both the server and client agree on the seed, most randomizing algorithm will output the same values.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .