I have a set of questions, where each question has a "Group" property.
I would like to extract a set containing one random question from each group.
I've tried the following LINQ query:
_questions = _questions.GroupBy(q => q.Group)
.Select(g => g.ElementAt(new Random().Next(0, g.Count())))
.ToList();
But it looks like the random.Next value is only calculated once, so the same generated value is used on each group?
That's probably how it's supposed to work (or I'm missing something), but what do I do if I want to generate a new random number for each group when selecting an element from that group?
Obviously this can be solved "the hard way", but can I do it with a LINQ query?
Regards