www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - partialShuffle only shuffles subset.

reply "BlackEdder" <edder tkwsping.nl> writes:
The documentation seems to indicate that partialShuffle: 
Partially shuffles the elements of r such that upon returning 
r[0..n] is a random subset of r, (which is what I want), but it 
seems that partialShuffle actually only shuffles the first subset 
of the range (which you could do probably also do by 
[0..n].randomShuffle).

This different behaviour was problem created since: 
https://issues.dlang.org/show_bug.cgi?id=11738. Does anyone know 
what the intended behaviour is/was?
May 19 2015
parent reply "Ivan Kazmenko" <gassa mail.ru> writes:
On Tuesday, 19 May 2015 at 10:00:33 UTC, BlackEdder wrote:
 The documentation seems to indicate that partialShuffle: 
 Partially shuffles the elements of r such that upon returning 
 r[0..n] is a random subset of r, (which is what I want), but it 
 seems that partialShuffle actually only shuffles the first 
 subset of the range (which you could do probably also do by 
 [0..n].randomShuffle).

 This different behaviour was problem created since: 
 https://issues.dlang.org/show_bug.cgi?id=11738. Does anyone 
 know what the intended behaviour is/was?
Reading the current documentation and unittests, I now also believe the fix was a mistake. Reopened the issue for now with a comment: https://issues.dlang.org/show_bug.cgi?id=11738#c2 I hope Joseph Rushton Wakeling looks into it soon.
May 19 2015
parent "Joseph Rushton Wakeling" <joseph.wakeling webdrake.net> writes:
On Tuesday, 19 May 2015 at 14:31:21 UTC, Ivan Kazmenko wrote:
 On Tuesday, 19 May 2015 at 10:00:33 UTC, BlackEdder wrote:
 The documentation seems to indicate that partialShuffle: 
 Partially shuffles the elements of r such that upon returning 
 r[0..n] is a random subset of r, (which is what I want), but 
 it seems that partialShuffle actually only shuffles the first 
 subset of the range (which you could do probably also do by 
 [0..n].randomShuffle).

 This different behaviour was problem created since: 
 https://issues.dlang.org/show_bug.cgi?id=11738. Does anyone 
 know what the intended behaviour is/was?
Reading the current documentation and unittests, I now also believe the fix was a mistake. Reopened the issue for now with a comment: https://issues.dlang.org/show_bug.cgi?id=11738#c2 I hope Joseph Rushton Wakeling looks into it soon.
Reading the documentation it does appear that the function behaviour is at odds with what is described. I don't know how I came to that misunderstanding. In the short term, if you want a randomly-shuffled random subset of a range, you could get it via something like, original_range.randomSample(n).array.randomShuffle; or maybe better original_range.randomShuffle.randomSample(n);
May 20 2015