From: gdefty@... Date: 2008-08-07T18:35:28+09:00 Subject: [ruby-core:18164] Re: New array methods cycle, choice, shuffle (plus bug in cycle) In message "Re: [ruby-core:18133] Re: New array methods cycle, choice, shuffle (plus bug in cycle)" On Thu, August 07, 2008, 14:48:00 Yukihiro Matsumoto wrote: | on Tue, 5 Aug 2008 23:37:57 +0900, "Martin DeMello" writes: | ||The second point looks wrong to me - I'd expect sample! to remove a ||random set of elements from the array without disturbing the ordering ||of the remaining elements. |Then what your expectation works for? I cannot think of a situation |where the difference means much. Is there any use-case for it? I have the same expectation of the order being preserved. It is not because I have any particular reason to preserve it, but simply because that is how I would expect a reasonable implementation to work. The problem with the shuffle-and-shift solutions is that they do not scale well with the size of the array. It is fine for small amounts of data (e.g. the rock-paper-scissors example) but not how I would expect a built-in method to be coded, where the size of the array can not be known in advance. If I take a sample of one or two elements out of an array of thousands of items, I would expect to generate one or two random numbers, not thousands. (And the next time a sample is taken, generate thousands more, because more items may have been added to the array since the last sample). It is in such a case that the difference becomes evident. Regards, graeme