I have a problem with my code. I want to have string output without repetitions. I have stuck here for 1 week.
I have already tried RemoveAdd
but I am still getting an error.
This is my code
public void StringRandom()
{
Random bsd = new Random();
string[] femalePetNames = { "Maggie", "Penny", "Saya", "Princess",
"Abby", "Laila", "Sadie", "Olivia",
"Starlight", "Talla" };
int fIndex = bsd.Next(0, femalePetNames.Length);
txttBox2.Text = femalePetNames[fIndex];
}
One output is the following: laila,sadie,laila, olivia........ (repetition)
Hope you guys can give me any help. Thanks
UPDATE ------------------------------------------------------------------------------
i just try solution from Marty Thompson and some code could be litle error . But i have try to fix it and YESSS that output have string random without repetition. Big thanks for Matty Thompson and all you guys
This is new correct code
List<string> femalePetNames = new List<string> { "Maggie", "Penny", "Saya", "Princess",
"Abby", "Laila", "Sadie", "Olivia",
"Starlight", "Talla" };
private void Button_Click(object sender, RoutedEventArgs e)
{
if (femalePetNames.Count > 0)
{
Random bsd = new Random();
int fIndex = bsd.Next(0, femalePetNames.Count);
txtbox.Text = femalePetNames[fIndex];
femalePetNames.RemoveAt(fIndex);
}
}