Okay, the title might be kind of misleading, but I couldn't really come up with a better explanation for my problem. I'm trying to create a program that takes an array of first names and an array of last names, and puts these together in an array of full names. Problem here is that I'm trying to make sure that the same name doesn't occur twice, so that if a combination of firstname[randomindex] and lastname[randomindex] is already in the full names array, it will reroll the random number used for index untill it finds a combination that has not been used. So far I'm kinda stuck at this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _100randompersons
{
class Fyldefylde
{
private string[] firstnames;
private string[] lastnames;
private string[] fullnames;
private Random random;
public Fyldefylde()
{
firstnames = new string[10] { "Kim", "Allan", "Frank", "Lone", "Line", "Anne", "Per", "Bo", "Grethe", "Mette" };
lastnames = new string[10] { "Pedersen", "Nielsen", "Hansen", "Larsen", "Nygaard", "Harboe", "Bendix", "Højris", "Pilgaard", "Nyager" };
fullnames = new string[100];
random = new Random();
}
public string[] getFirstNames()
{
return firstnames;
}
public string[] getLastNames()
{
return lastnames;
}
public string[] getFullNames()
{
return fullnames;
}
public int getRandomIndex(int min, int max)
{
int randomnumber = random.Next(min, max);
return randomnumber;
}
public void fillFullNames()
{
for(int i = 0; i < fullnames.Length; i++)
{
getRandomIndex(0, 10);
while(fullnames.Contains(firstnames[getRandomIndex(0,10)] + " " + lastnames[getRandomIndex(0,10)]))
{
fullnames[i] = firstnames[getRandomIndex(0, 10)] + " " + lastnames[getRandomIndex(0, 10)];
}
}
}
}
}
Thanks in advance! :)