I’m pretty sure I understand the concept here. I’ve written a simple Unity C# script to implement it with a user defined number of players. My question is why would you do this instead of just generating a random number between, 0 and 3 for 4 players?
using System.Collections.Generic;
using UnityEngine;
public class WhoGoesFirstUsingRemainder : MonoBehaviour
{
[SerializeField] int numberOfPlayers;
void Start()
{
Debug.Log(WhoGoesFirst(GeneratePlayers()) + " goes first!");
}
private string WhoGoesFirst(List<string> _players)
{
System.Random rnd = new System.Random();
int rndNumber = rnd.Next(numberOfPlayers, 1001);
int remainder = rndNumber % numberOfPlayers;
Debug.Log(numberOfPlayers + " Players, using " + rndNumber + " to find the remainder");
return _players[remainder];
}
private List<string> GeneratePlayers()
{
List<string> players = new List<string>();
int index = 0;
while (index < numberOfPlayers)
{
index++;
players.Add("Player" + index);
}
return players;
}
}