Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C087610E85 for ; Fri, 9 Aug 2013 13:10:50 +0000 (UTC) Received: (qmail 91057 invoked by uid 500); 9 Aug 2013 13:10:50 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 90003 invoked by uid 500); 9 Aug 2013 13:10:49 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 89448 invoked by uid 99); 9 Aug 2013 13:10:47 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Aug 2013 13:10:47 +0000 Date: Fri, 9 Aug 2013 13:10:47 +0000 (UTC) From: "Gilles (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (MATH-1019) "shuffle" method broken (in class "o.a.c.m.random.RandomDataGenerator") MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/MATH-1019?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13734748#comment-13734748 ] Gilles commented on MATH-1019: ------------------------------ With the replacement, the unit test "testNextPermutation()" passes but it uses a fully shuffled array where there is no difference in behaviour between the old (in "RandomDataGenerator") and the fixed (in "MathArrays") code. > "shuffle" method broken (in class "o.a.c.m.random.RandomDataGenerator") > ----------------------------------------------------------------------- > > Key: MATH-1019 > URL: https://issues.apache.org/jira/browse/MATH-1019 > Project: Commons Math > Issue Type: Bug > Affects Versions: 3.2 > Reporter: Gilles > Fix For: 3.3 > > > The method does not abide by its contract: elements before the "end" index are included in the shuffle. > {code} > /** > * Uses a 2-cycle permutation shuffle to randomly re-order the last elements > * of list. > * > * @param list list to be shuffled > * @param end element past which shuffling begins > */ > private void shuffle(int[] list, int end) { > int target = 0; > for (int i = list.length - 1; i >= end; i--) { > if (i == 0) { // XXX "0" should be "end" > target = 0; // XXX "0" should be "end" > } else { > // NumberIsTooLargeException cannot occur > target = nextInt(0, i); // XXX "0" should be "end" > } > int temp = list[target]; > list[target] = list[i]; > list[i] = temp; > } > } > {code} > I'm going to introduce the above corrections in the new implementation to be located in "MathArrays" (cf. issue MATH-1010). -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira