Create two random teams from a list of players The task is to create two random teams from a list of players.

Given an example of players = ["John", "Mike", "Alice", "Bob"]

One example random team would be:

team1 = ["Mike", "Alice"];
team2 = ["John", "Bob"];


This is my solution but I'm not sure how efficient it is because random can create same number for a number of times.

The question to separate equally and randomly without repeating the same player.

using System;
using System.Collections.Generic;

public class Program
{

    public static void Main(string[] args)
    {
        Random rnd = new Random();
        var numbers = new List&lt;int&gt;();

        var ilkListe = new List&lt;int&gt;();

        var ikinciListe = new List&lt;int&gt;();

        numbers.Add(1);
        numbers.Add(2);
        numbers.Add(3);
        numbers.Add(4);
        numbers.Add(5);
        numbers.Add(6);
        numbers.Add(7);
        numbers.Add(8);
        numbers.Add(9);
        numbers.Add(10);
        Console.WriteLine("LIST 1: " + numbers.Count);

        do {
            int sayi = numbers[rnd.Next(numbers.Count)];
            if (!(ilkListe.Contains(sayi))) {
                Console.WriteLine(sayi);
                ilkListe.Add(sayi);
            }
        }

        while (ilkListe.Count &lt; numbers.Count / 2);

        Console.WriteLine("Ikinci liste");

        do {
            int sayi = numbers[rnd.Next(numbers.Count)];
            if (!(ilkListe.Contains(sayi)) &amp;&amp; !(ikinciListe.Contains(sayi))) {
                Console.WriteLine(sayi);
                ikinciListe.Add(sayi);
            }
        }

        while (ikinciListe.Count &lt; numbers.Count / 2);
    }
}
Review


Don't use the main entry point to implement an algorithm. Create a method instead.
Think about how to allow this method to be usable for all kinds of types, not just integers. You have implemented the algorithm for integers, yet you show an example with strings.
When creating an algorithm, surely you have made some unit tests, at least for the happy paths. Feel free to include them in the question.
Use clear variable names, and stick to one written language.
Don't mix algorithm logic with Console output.


A possible method signature could be:

public static IEnumerable&lt;IEnumerable&lt;T&gt;&gt; SplitRandom&lt;T&gt;(
    this IEnumerable&lt;T&gt; source, int targetCount)
{
    // .. algorithm implementation
}


Called as..

var names = new [] { "John", "Mike", "Alice", "Bob" };
var teams = names.SplitRandom(2);


Or as..

var numbers = Enumrable.Range(1, 10);
var numberGroups = numbers.SplitRandom(2);