Geeks With Blogs
Guilherme Cardoso, Blog EN .NET geek
I've seen a few guys asking on stack overflow and forums how to order randomly using LINQ.
Here's a simple solution using Guid:

OrderBy(x => System.Guid.NewGuid()) Posted on Wednesday, March 30, 2011 12:54 AM | Back to top


Comments on this post: LINQ - Order Randomly

# re: LINQ - Order Randomly
Requesting Gravatar...
don't think that will be random.

Guids are unique, yes, but they have a structure to them. The first 60bits are a time stamp for starters.
Left by Keith Nicholas on Mar 30, 2011 1:00 PM

# re: LINQ - Order Randomly
Requesting Gravatar...
also seems odd since there is a random number generator in .NET :)
Left by Keith Nicholas on Mar 30, 2011 1:03 PM

# re: LINQ - Order Randomly
Requesting Gravatar...
OrderBy is O(n log n). It would be better to use an algorithm like Fisher-Yates which is O(n).

http://stackoverflow.com/questions/375351/most-efficient-way-to-randomly-sort-shuffle-a-list-of-integers-in-c/375446#375446
Left by Ryan on Mar 30, 2011 7:34 PM

Your comment:
 (will show your gravatar)


Copyright © Guilherme Cardoso | Powered by: GeeksWithBlogs.net