From: Justin Collins Date: 2008-12-30T16:21:18+09:00 Subject: [ruby-core:20986] Re: [Feature #929] Array#shuffle does not initialize random seed Kurt Stephens wrote: > Not a bug; it's a feature? The best thing about pseudorandom generators *is* > that they are not random. :) > > Justin Collins wrote: > >> Feature #929: Array#shuffle does not initialize random seed >> http://redmine.ruby-lang.org/issues/show/929 >> >> Author: Justin Collins >> Status: Open, Priority: Low >> Category: core, Target version: 1.9.1 Release Candidate >> >> Unlike calling Kernel#rand, Array#shuffle and Array#shuffle! do not automatically seed the random number generator. This means subsequent runs of the same program will produce the same shuffles unless a separate call is made to Kernel#rand or Kernel#srand. >> >> For example, running just >> >> ruby -e 'p Array.new(50) {|n| n }.shuffle' >> >> will always give the same output. >> >> >> ---------------------------------------- >> http://redmine.ruby-lang.org >> >> Well, both behaviors are available, it is just a matter of which one is more convenient. Apparently this has already been changed (my mistake, I did not see the revision anywhere), but I would argue (if I had to) that one would usually desire subsequent runs of the program to produce different, pseudorandom results. On the less common (in my opinion) occasion, when a specific starting seed is required, then one can use srand(seed) first. This is also consistent with the behavior of Kernel#rand. -Justin