Order by Random in C#
AnyEnumerable.OrderBy(_ => Guid.NewGuid())
Written by Chad Moran
Related protips
4 Responses
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
·
Anyways, I prefer my implementation because it catches argument errors earlier.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#