<p>In general, the best way to &quot;sync&quot; PRNGs between two programs in different languages is to implement the same PRNG in both languages.</p>
<p>For your purposes, a linear congruential generator (LCG) is a simple PRNG if you only want &quot;something that looks random (though it doesn't have to be secure)&quot;. This kind of generator is trivial to implement in both C# and Python.</p>
<p>One example, among many other possibilities, is the following 32-bit LCG (where <code>x</code> is the seed):</p>
<p>C#:</p>
<pre><code>// Generate the next x from the current one.
unchecked {
    // NOTE: x is an `int`
    x = ((int)0xadb4a92d * x) + 9999999;
}
</code></pre>
<p>Python:</p>
<pre><code># Generate the next x from the current one.
x = ((0xadb4a92d * x) + 9999999) &amp; 0xFFFFFFFF
</code></pre>
<p>See section 8 of the very very recent <a href="https://arxiv.org/pdf/2001.05304.pdf" rel="nofollow noreferrer">paper by Steele and Vigna</a> for other parameter choices as well as a review of the theory involving LCGs.</p>
<p>However, LCGs are far from perfect. (For instance, the above LCG produces <code>x</code>'s with weak low bits, so that, e.g., every other <code>x</code> is odd and every other <code>x</code> is even.) And in general, LCGs, especially those with 32-bit seeds or other short seeds, are far from appropriate for many situations, including scientific work or information security. In case you want another choice for a PRNG, I list <a href="https://peteroupc.github.io/hqprng.html" rel="nofollow noreferrer">many of them</a>.</p>
How to sync a PRNG between C#/Unity and Python?
<p>I have a game implemented in Unity/C# that generates simple environments using the built-in PRNG (<code>UnityEngine.Random</code>). 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?</p>

<p>Some solutions I have considered so far:</p>

<ul>
<li>Attempt to reimplement Python's default random number generator (<code>random</code>) in C#. The source code is available, but fairly long so may difficult to implement in practice.</li>
<li>Attempt to reimplement <code>UnityEngine.Random</code> 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.</li>
<li>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. <a href="https://en.wikipedia.org/wiki/List_of_random_number_generators" rel="nofollow noreferrer">Wikipedia</a> has a long list of PRNGs, and I have no idea the difficulty in implementing each of them.</li>
<li>Or maybe someone else has done this at some point...? I couldn't find anything online, though.</li>
</ul>

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

<p>Thanks!</p>