From: Martin DeMello Date: 2008-08-08T02:40:28+09:00 Subject: [ruby-core:18172] Re: New array methods cycle, choice, shuffle (plus bug in cycle) On Thu, Aug 7, 2008 at 3:11 AM, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: [ruby-core:18164] Re: New array methods cycle, choice, shuffle (plus bug in cycle)" > on Thu, 7 Aug 2008 18:35:28 +0900, gdefty@attglobal.net writes: > > |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. > > I am against #sample! for the name. If one try to persuade me to add > a method with the behavior, the name should be anything but #sample! The name seems good to me - it ties in with the statistical usage of sample-with-replacement and sample-without-replacement. Maybe #pick! instead. It seems analogous to having #slice and #slice! > I believe the calculation complexity of shuffle-once-and-pop is far > lesser than pick-some-elements-and-remove-them, even with an array of > thousands of elements. As a first step, we could have #delete_at accept multiple arguments, and optimise it in C to delete multiple elements efficiently. Does #sample already take not selecting the same element twice into account? martin