Question: I have an XML file from which I am parsing some content to display in a list:

### Class:

```c
public class SampleClass 
{
    public string Sample {get; set;}    
    public string Definite {get; set;}
    public string Random {get; set;}
}

```

### XML File Sample:

```xml
<Question>
    <Sample>This is sample 1</Sample>
    <Definite>Answer 1</Definite>
</Question>

<Question>
    <Sample>This is sample 2</Sample>
    <Definite>Answer 2</Definite>
</Question>
...

```

Currently, I am parsing content from the list easily and making this list.

```c
_list = xmlDoc.Descendants("Question")
              .Select(
                  q => new SampleClass 
                  { 
                      Sample = q.Element("Sample").Value, 
                      Definite = q.Element("Definite").Value
                  })
              .ToList();

```

However, in the list I want to include another element that is to be parsed from the XML file in a random order eg:

```
SampleClass list   Sample        Definite   Random 
                      ^              ^        ^ 
List element 1: This is sample 1, Answer 1, Answer5
List element 2: This is sample 2, Answer 2, Answer1
List element 3: This is sample 3, Answer 3, Answer4 ...

```

I wanted to ask how do I include this `Random` element in the list while parsing such that `q.Random` is assigned a random `<Definite> Value </Definite>` from the `Question` nodes?

Duplicates of random in the list are not acceptable.

Answer: 
Do it in 2 passes. The first pass can be identical to what you already have. The second pass will assign a random answer to each item in the list.

This is off the top of my head, so forgive any bugs, but it will look something like the following:

```
IList<string> randomAnswers = _list
    .Select(c => c.Definite)
    .OrderBy(c => Guid.NewGuid())
    .ToList();

for (int index = 0; index < randomAnswers.Length; index++)
{
    _list[index].Random = randomAnswers[index];
}

```
This should be what you're looking for:

```
var rnd = new Random(); //make this a static field, if needed
var questions = xmlDoc.Descendants("Question").ToList();
_list = _questions.Select(q => new SampleClass
{
    Sample = q.Element("Sample").Value,
    Definite = q.Element("Definite").Value,
    Random = questions[rnd.Next(questions.Count)].Element("Definite").Value
}).ToList();

```

(from [Access random item in list](https://stackoverflow.com/questions/2019417/access-random-item-in-list))

Note that this will allow duplicate random answers, e.g. answer 1 could be the Random for 2 and 3, and doesn't prevent an answer from being the Random for itself. If these are problems, you'll need to use a different solution (maybe a variation on this).