2

I have an IEnumerator which has collection of some pictures(Enumarator of PictureCollection object). I want this to appear in random order, means the pictures can appear at random index. Is there any inbuilt C# method to do that or any workaround?

0xC0DED00D
  • 19,522
  • 20
  • 117
  • 184

1 Answers1

3

You might need to shuffle the elements of an IEnumerable in a random way.

Random rand = new Random();
var models = garage.OrderBy(c => rand.Next()).Select(c => c.Model).ToList();

Taken from here.

Community
  • 1
  • 1
VasileF
  • 2,856
  • 2
  • 23
  • 36
  • 1
    I don't think the select is required. – Reactgular Dec 11 '13 at 22:51
  • Excellent that's what I required. Although I was talking about IEnumerator, not IEnumerable, but I am using a List instead of IEnumerator anyways now. Thanks and yeah I didn't require Select :-) – 0xC0DED00D Dec 11 '13 at 23:14