From: Denis Hennessy Date: 2008-01-18T21:14:13+09:00 Subject: Re: [SUMMARY] Counting Cards (#152) On 18 Jan 2008, at 09:19, Gareth Adams wrote: > Ruby Quiz grayproductions.net> writes: > >> size.times do |i| >> j = rand(size) >> @shoe[i],@shoe[j] = @shoe[j],@shoe[i] >> end >> (the code is just a longhand form of @shoe.sort_by { rand }). > > Easy to think that, but this is the exact same definition of a > "naive algorithm" > demonstrated recently and very well summed up by Jeff Atwood: > > http://www.codinghorror.com/blog/archives/001015.html > > Gareth That's very interesting. The core of the bug is the the original algorithm generates 52*52 possible outcomes, instead of 52! outcomes. The non-randomness occurs because 52*52 is not evenly dividable by 52!. Also interesting that you can learn new things by reading C# code... /dh >