This is Lukas M's Typepad Profile.
Join Typepad and start following Lukas M's activity
Already a member?
Update has been hidden from all public facing feeds in Typepad
I hope this comment will bubble up. Post has a lot of good details, but there is a problem with the second code in C#. var cards = Enumerable.Range(0, 51); var shuffledcards = cards.OrderBy(a => Guid.NewGuid()); There are two problems with it covered by Eric Lippert: Do not use a random function as a comparator and feed that to a sorting algorithm. Sort algorithms are permitted to do anything they please if the comparator is bad, including crashing, and including producing non-random results. As Microsoft recently found out, it is extremely embarrassing to get a simple algorithm like this wrong. Do not sort on a "random" GUID as your key. GUIDs are guaranteed to be unique. They are not guaranteed to be randomly ordered. It is perfectly legal for an implementation to spit out consecutive GUIDs. Source: http://stackoverflow.com/questions/5519385/calling-a-list-of-methods-in-a-random-sequence/5519621#5519621 Kind Regards, Lukas M
Commented Apr 13, 2011 on
Pop quiz, hotshot. How would you write code to shuffle a deck of cards? I was thinking about this after reading Mike's card-shuffling algorithm woes: Here's where the non-CS mind comes into play. My first thought was to generate an unshuffled deck as an array-like structure -- all cards in ord...
Lukas M is now following
The Typepad Team
Apr 13, 2011
Subscribe to Lukas M’s Recent Activity
View all »
Around The Web
All Rights Reserved.
Terms of Service