From: Mathieu Bouchard Date: 2001-05-08T14:10:38+09:00 Subject: [ruby-talk:14843] Re: How to do it the Ruby-way 3 On Tue, 1 May 2001, Stefan Matthias Aust wrote: > Is there a similar built-in mehtod in Ruby? no > BTW, is there just one global random number generator? i think so. Kernel#rand > It's of course easy to add (see below - code improvements are welcomed!), > def shuffle! > len = length > (0...len).each {|i| > j = rand len > self[i], self[j] = self[j], self[i] > } Why this and not the following? > j = i + rand(len-i) I'm not really good at probabilities, but it seems to me that the latter makes a perfectly fair shuffler (given a perfectly fair rand() function), and that your "j = rand len" cannot make a perfectly fair shuffler, because N**N is usually not divisible by factorial(N). It's nonetheless possible that yours is very close to being a fair one; can you show me that it is? matju