You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Dennis Hendriks (Created) (JIRA)" <ji...@apache.org> on 2011/12/07 15:06:39 UTC

[jira] [Created] (MATH-720) RandomDataImpl uses both JDKRandomGenerator and Well19937c, while contract/javadoc only specifies Well19937c.

RandomDataImpl uses both JDKRandomGenerator and Well19937c, while contract/javadoc only specifies Well19937c.
-------------------------------------------------------------------------------------------------------------

                 Key: MATH-720
                 URL: https://issues.apache.org/jira/browse/MATH-720
             Project: Commons Math
          Issue Type: Bug
    Affects Versions: 3.0
            Reporter: Dennis Hendriks
         Attachments: TestRandom.java

See attached unit test. I create a distribution, sample it (not printed), set the seed to 0, and then print the next sample. I also create the same distribution again, set the seed to 0, and then print the next sample. I expect the same sample, as in both cases the seed was set to 0, just before sampling. I however get this output:

{code}
5
4
{code}

The problem is in the org.apache.commons.math.random.RandomDataImpl class:
 - The RandomDataImpl(RandomGenerator rand) constructor states in javadoc: "@param rand the source of (non-secure) random data (may be null, resulting in default JDK-supplied generator)"
 - reSeed(long seed) method does: if (rand == null) rand = new JDKRandomGenerator();
 - reSeed() method does: if (rand == null) rand = new JDKRandomGenerator();
 - class javadoc states: "If no <code>RandomGenerator</code> is provided in the constructor, the default is to use a Well19937c generator."
 - getRan() does: if (rand == null) rand = new Well19937c(System.currentTimeMillis() + System.identityHashCode(this));
 - getRan() states in javadoc: "Creates and initializes a default generator if null. Uses a Well19937c generator with System.currentTimeMillis() + System.identityHashCode(this)) as the default seed."

It seems that only Well19937c should be used, but the constructor javadoc, and the implementation of the reSeed methods was not updated to match this. I think the partial changes were done in MATH-701, more specifically, in commit [1197626] (and related commit [1197716]).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (MATH-720) RandomDataImpl uses both JDKRandomGenerator and Well19937c, while contract/javadoc only specifies Well19937c.

Posted by "Phil Steitz (Resolved) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-720?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Phil Steitz resolved MATH-720.
------------------------------

    Resolution: Fixed

Fixed in r1213130.
                
> RandomDataImpl uses both JDKRandomGenerator and Well19937c, while contract/javadoc only specifies Well19937c.
> -------------------------------------------------------------------------------------------------------------
>
>                 Key: MATH-720
>                 URL: https://issues.apache.org/jira/browse/MATH-720
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: Nightly Builds
>            Reporter: Dennis Hendriks
>              Labels: random, seed
>             Fix For: 3.0
>
>         Attachments: TestRandom.java
>
>
> See attached unit test. I create a distribution, sample it (not printed), set the seed to 0, and then print the next sample. I also create the same distribution again, set the seed to 0, and then print the next sample. I expect the same sample, as in both cases the seed was set to 0, just before sampling. I however get this output:
> {code}
> 5
> 4
> {code}
> The problem is in the org.apache.commons.math.random.RandomDataImpl class:
>  - The RandomDataImpl(RandomGenerator rand) constructor states in javadoc: "@param rand the source of (non-secure) random data (may be null, resulting in default JDK-supplied generator)"
>  - reSeed(long seed) method does: if (rand == null) rand = new JDKRandomGenerator();
>  - reSeed() method does: if (rand == null) rand = new JDKRandomGenerator();
>  - class javadoc states: "If no <code>RandomGenerator</code> is provided in the constructor, the default is to use a Well19937c generator."
>  - getRan() does: if (rand == null) rand = new Well19937c(System.currentTimeMillis() + System.identityHashCode(this));
>  - getRan() states in javadoc: "Creates and initializes a default generator if null. Uses a Well19937c generator with System.currentTimeMillis() + System.identityHashCode(this)) as the default seed."
> It seems that only Well19937c should be used, but the constructor javadoc, and the implementation of the reSeed methods was not updated to match this. I think the partial changes were done in MATH-701, more specifically, in commit [1197626] (and related commit [1197716]).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (MATH-720) RandomDataImpl uses both JDKRandomGenerator and Well19937c, while contract/javadoc only specifies Well19937c.

Posted by "Gilles (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-720?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13164783#comment-13164783 ] 

Gilles commented on MATH-720:
-----------------------------

Good catch!

This bug shows how safer it would be to have the "rand" field "final" (no need to test for "null" all over the place).

                
> RandomDataImpl uses both JDKRandomGenerator and Well19937c, while contract/javadoc only specifies Well19937c.
> -------------------------------------------------------------------------------------------------------------
>
>                 Key: MATH-720
>                 URL: https://issues.apache.org/jira/browse/MATH-720
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.0
>            Reporter: Dennis Hendriks
>              Labels: random, seed
>         Attachments: TestRandom.java
>
>
> See attached unit test. I create a distribution, sample it (not printed), set the seed to 0, and then print the next sample. I also create the same distribution again, set the seed to 0, and then print the next sample. I expect the same sample, as in both cases the seed was set to 0, just before sampling. I however get this output:
> {code}
> 5
> 4
> {code}
> The problem is in the org.apache.commons.math.random.RandomDataImpl class:
>  - The RandomDataImpl(RandomGenerator rand) constructor states in javadoc: "@param rand the source of (non-secure) random data (may be null, resulting in default JDK-supplied generator)"
>  - reSeed(long seed) method does: if (rand == null) rand = new JDKRandomGenerator();
>  - reSeed() method does: if (rand == null) rand = new JDKRandomGenerator();
>  - class javadoc states: "If no <code>RandomGenerator</code> is provided in the constructor, the default is to use a Well19937c generator."
>  - getRan() does: if (rand == null) rand = new Well19937c(System.currentTimeMillis() + System.identityHashCode(this));
>  - getRan() states in javadoc: "Creates and initializes a default generator if null. Uses a Well19937c generator with System.currentTimeMillis() + System.identityHashCode(this)) as the default seed."
> It seems that only Well19937c should be used, but the constructor javadoc, and the implementation of the reSeed methods was not updated to match this. I think the partial changes were done in MATH-701, more specifically, in commit [1197626] (and related commit [1197716]).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (MATH-720) RandomDataImpl uses both JDKRandomGenerator and Well19937c, while contract/javadoc only specifies Well19937c.

Posted by "Dennis Hendriks (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-720?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dennis Hendriks updated MATH-720:
---------------------------------

    Attachment: TestRandom.java

TestRandom.java: shows the problem, as described in the issue description.
                
> RandomDataImpl uses both JDKRandomGenerator and Well19937c, while contract/javadoc only specifies Well19937c.
> -------------------------------------------------------------------------------------------------------------
>
>                 Key: MATH-720
>                 URL: https://issues.apache.org/jira/browse/MATH-720
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.0
>            Reporter: Dennis Hendriks
>              Labels: random, seed
>         Attachments: TestRandom.java
>
>
> See attached unit test. I create a distribution, sample it (not printed), set the seed to 0, and then print the next sample. I also create the same distribution again, set the seed to 0, and then print the next sample. I expect the same sample, as in both cases the seed was set to 0, just before sampling. I however get this output:
> {code}
> 5
> 4
> {code}
> The problem is in the org.apache.commons.math.random.RandomDataImpl class:
>  - The RandomDataImpl(RandomGenerator rand) constructor states in javadoc: "@param rand the source of (non-secure) random data (may be null, resulting in default JDK-supplied generator)"
>  - reSeed(long seed) method does: if (rand == null) rand = new JDKRandomGenerator();
>  - reSeed() method does: if (rand == null) rand = new JDKRandomGenerator();
>  - class javadoc states: "If no <code>RandomGenerator</code> is provided in the constructor, the default is to use a Well19937c generator."
>  - getRan() does: if (rand == null) rand = new Well19937c(System.currentTimeMillis() + System.identityHashCode(this));
>  - getRan() states in javadoc: "Creates and initializes a default generator if null. Uses a Well19937c generator with System.currentTimeMillis() + System.identityHashCode(this)) as the default seed."
> It seems that only Well19937c should be used, but the constructor javadoc, and the implementation of the reSeed methods was not updated to match this. I think the partial changes were done in MATH-701, more specifically, in commit [1197626] (and related commit [1197716]).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (MATH-720) RandomDataImpl uses both JDKRandomGenerator and Well19937c, while contract/javadoc only specifies Well19937c.

Posted by "Phil Steitz (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-720?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Phil Steitz updated MATH-720:
-----------------------------

    Affects Version/s:     (was: 3.0)
                       Nightly Builds
        Fix Version/s: 3.0
    
> RandomDataImpl uses both JDKRandomGenerator and Well19937c, while contract/javadoc only specifies Well19937c.
> -------------------------------------------------------------------------------------------------------------
>
>                 Key: MATH-720
>                 URL: https://issues.apache.org/jira/browse/MATH-720
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: Nightly Builds
>            Reporter: Dennis Hendriks
>              Labels: random, seed
>             Fix For: 3.0
>
>         Attachments: TestRandom.java
>
>
> See attached unit test. I create a distribution, sample it (not printed), set the seed to 0, and then print the next sample. I also create the same distribution again, set the seed to 0, and then print the next sample. I expect the same sample, as in both cases the seed was set to 0, just before sampling. I however get this output:
> {code}
> 5
> 4
> {code}
> The problem is in the org.apache.commons.math.random.RandomDataImpl class:
>  - The RandomDataImpl(RandomGenerator rand) constructor states in javadoc: "@param rand the source of (non-secure) random data (may be null, resulting in default JDK-supplied generator)"
>  - reSeed(long seed) method does: if (rand == null) rand = new JDKRandomGenerator();
>  - reSeed() method does: if (rand == null) rand = new JDKRandomGenerator();
>  - class javadoc states: "If no <code>RandomGenerator</code> is provided in the constructor, the default is to use a Well19937c generator."
>  - getRan() does: if (rand == null) rand = new Well19937c(System.currentTimeMillis() + System.identityHashCode(this));
>  - getRan() states in javadoc: "Creates and initializes a default generator if null. Uses a Well19937c generator with System.currentTimeMillis() + System.identityHashCode(this)) as the default seed."
> It seems that only Well19937c should be used, but the constructor javadoc, and the implementation of the reSeed methods was not updated to match this. I think the partial changes were done in MATH-701, more specifically, in commit [1197626] (and related commit [1197716]).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira