I am trying to shuffle cards in a deck using the same random seed so the decks will be random, but synced on both clients. I am using the following shuffle algorithm:
internal void ShuffleDeck(int randomSeed)
_random = new Random(randomSeed);
Cards.Card toShuffle = CardsInDeck.ToArray();
CardsInDeck = toShuffle.ToList<Cards.Card>();
/// Shuffle the array.
/// <typeparam name="T">Array element type.</typeparam>
/// <param name="array">Array to shuffle.</param>
private static void Shuffle<T>(T array)
int n = array.Length;
for (int i = 0; i < n; i++)
// NextDouble returns a random number between 0 and 1.
// ... It is equivalent to Math.random() in Java.
int r = i + (int)(_random.NextDouble() * (n - i));
T t = array[r];
array[r] = array[i];
array[i] = t;
In order to do this, you need to make sure that both machines are using the exact same seed and the same random number generator. There's no guarantee that different versions of the
Random class will use the same algorithm.
So you need to develop your own random number generator class and use it instead of