This is my server code:
Random random = new Random();
int randomSeed = random.Next(1, 2147483647);
random = new Random(randomSeed);
int random1 = random.Next(1, 100);
int random2 = random.Next(1, 1000);
int random3 = random.Next(1, 10000);
int random4 = random.Next(1, 100000);
int random5 = random.Next(1, 1000000);
The randomSeed is then sent to the client which generates random 1-5 again.
They’re both using System.Random
In my results, around 50% of the time the values are identical but the other 50% of the time my client’s value is exactly 1 lower than the server’s value.
Here’s one example:
27 / 26
926 / 926
1628 / 1627
83052 / 83052
965754 / 965754
My client is a game I’m making in Unity.
The server is a C# Module hosted on Unity’s servers (UGS C# Cloud Code Modules)
It might just be caused by the different .NET versions.
I’ve been researching how to fix this for a few hours, but it’s all way too complicated for me to understand.
I’ve seen several other methods of Random generation, but I don’t understand which one to use or why and most importantly how I would implement them in my module.