I have an array with 100 elements, of which I randomly pick 4 (the same element can't be picked twice). I repeat this process many times, to try and get every possible combination. There must be a more efficiënt way though.
How would I go about creating a loop that just creates every possible combination?
double[][] picked = new double[4][];
int[] chosen = new int[4];
Random rnd = new Random();
List<int> exclude = new List<int>();
int z = 0;
while (z < 4)
{
picked[z] = new double[rows];
int x = rnd.Next(0, rows);
if (exclude.Contains(x))
{
continue;
}
exclude.Add(x);
// do stuff with the chosen elements
z++;
}
Edit: the question that was linked to as duplicate is different, as it allows for duplicate elements to be chosen.
Found my anwser here: https://stackoverflow.com/a/17871949/1880554