I have a little problem over here. I have a list of questions KlausimuList
and i have to form another list Atsitiktinis
witch would be a random length and would have random questions taken from KlausimuList
. My method works, but the problem is - questions are duplicating. Could you please write me a code where they don't? I have an idea of making a seperate int array of indexes of questions i already added, and then each time check if that question already is in that list. If it does - genererate a new number, but i just don't know how to write the code for this thing :D. Thanks in advice. Code is in c#.
static void FormuotiAtsisiktini(List<Klausimas> KlausimuList, ref List<Klausimas> Atsitiktinis)
{
Random kiek = new Random();
int kiekis = kiek.Next(1, KlausimuList.Count);
for (int i = 0; i < kiekis; i++)
Atsitiktinis.Add(KlausimuList[kiek.Next(1, KlausimuList.Count)]);
}