Guilherme Cardoso, Blog EN

.NET geek

  Home  |   Contact  |   Syndication    |   Login
  21 Posts | 0 Stories | 21 Comments | 0 Trackbacks

News

Name: Guilherme Cardoso
Age: 19
Country: Portugal


pontonetpt

NetPonto

xaml pt

Twitter





Archives

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

Feedback

# re: LINQ - Order Randomly 3/30/2011 1:00 PM Keith Nicholas
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.

# re: LINQ - Order Randomly 3/30/2011 1:03 PM Keith Nicholas
also seems odd since there is a random number generator in .NET :)

# re: LINQ - Order Randomly 3/30/2011 7:34 PM Ryan
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

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: