Select N random elements from a List in C#
I need a quick algorithm to select 5 random elements from a generic list. For example, I’d like to get 5 random elements from a List<string>. 32 Answers 32 Using linq: YourList.OrderBy(x => rnd.Next()).Take(5)