www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11738] New: partialShuffle actually shuffles the entire input

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11738

           Summary: partialShuffle actually shuffles the entire input
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: joseph.wakeling webdrake.net



2013-12-14 02:30:43 PST ---
Created an attachment (id=1301)
Test case to illustrate the bug.

partialShuffle(input, n) is supposed to shuffle input[0 .. n] and leave input[n
.. $] untouched.  In fact it shuffles the entire input.

This is illustrated by the attached code, where the second half of the
partially shuffled array should still read 5, 6, 7, 8, 9 but is actually
randomly rearranged.

It's trivially fixable: on std/random.d:L1480 the second argument to uniform()
should be n - i, not r.length - i.  A copy-paste error from an earlier
iteration of randomShuffle, perhaps? :-)

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 14 2013
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11738




Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/fbc8d1e08e122acb04306a21f73a3c5dd936a350
Fix Issue 11738 - partialShuffle should actually _be_ a partial shuffle :-)

This patch fixes the problem that partialShuffle was in fact invariably
shuffling the whole of the input, undetected because there were unittests
only for randomShuffle.

As well as the fix I've added some unittests specifically for partialShuffle
to ensure that it works properly, and I've taken the opportunity to tweak a
couple of bits of Ddoc and tidy up the randomShuffle unittests.

https://github.com/D-Programming-Language/phobos/commit/277ce347e917747fb048b3933100a9bd8fd768fe


Fix Issue 11738 - partialShuffle should actually _be_ a partial shuffle :-)

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 15 2013
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11738


Joseph Rushton Wakeling <joseph.wakeling webdrake.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 15 2013