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
|