mardi 6 février 2018

Pick a int from a List

This is what ive got so far, but it doesnt take into account if someone is already in a team. i.e.

Alex and John are going to be randomly assorted into the teams. Currently is the system puts Alex into team 1, it wont know that someone is in team 1 and could place John in team 1 also. This logic needs to also reflect if there are 4 teams and 16 people to be sorted etc. Can someone help?

List<int> teamsLeft = new List<int>();

            foreach (var item in namesOfAllPlayers)
            {
                if (!teamsLeft.Any())
                {
                    for (int i = 0; i < noOfTeams.Value; i++)
                        teamsLeft.Add(i + 1);
                }

                Random rnd = new Random();
                int team = rnd.Next(1, Convert.ToInt32(noOfTeams.Value));

After it determined what player is in the team it then extracts that team number from teamsLeft and continues. Once all teams have been extracted, meaning there have been 1 placed in each time more than previously, then it will refresh the teamsLeft.




Aucun commentaire:

Enregistrer un commentaire