lundi 20 janvier 2020

How to sync a PRNG between C#/Unity and Python?

I have a game implemented in Unity/C# that generates simple environments using the built-in PRNG (UnityEngine.Random). I am trying to reimplement the environment generation procedure in Python 3. I need the random number generators to be synchronized so that when provided with the same seed, the actual game in Unity and the Python reimplementation generate the exact same environment. What would be the best approach to synchronizing the two platforms?

Some solutions I have considered so far:

  • Attempt to reimplement Python's default random number generator (random) in C#. The source code is available, but fairly long so may difficult to implement in practice.
  • Attempt to reimplement UnityEngine.Random in Python. However, I don't have any source code, and even if I knew the class of PRNG used, there is no guarantee that I will be able to successfully reimplement it exactly the same.
  • Implement the same PRNG in both. However, I don't know what a good option for a PRNG is for my use case. I basically need something that looks random (though it doesn't have to be secure) and doesn't take more than an hour or two to put together. Wikipedia has a long list of PRNGs, and I have no idea the difficulty in implementing each of them.
  • Or maybe someone else has done this at some point...? I couldn't find anything online, though.

Any suggestions on the best approach, or a simple PRNG I can implement easily in both C# and Python?

Thanks!




Aucun commentaire:

Enregistrer un commentaire