Last Updated: February 25, 2016
·
8.866K
· chadmoran

Order by Random in C#

AnyEnumerable.OrderBy(_ => Guid.NewGuid())

4 Responses
Add your response

Hi, this is nice. Didn't thought about using Guid for randomizing enumerables. Clever!
But you have a typo in it.

over 1 year ago ·

@ppiotrowicz Fixed! Thanks.

over 1 year ago ·

This is much better: http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm

There's a discussion about it on SO: stackoverflow.com/questions/1287567/is-using-random-and-orderby-a-good-shuffle-algorithm/1287572

over 1 year ago ·