You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ps...@apache.org on 2011/11/05 07:48:13 UTC
svn commit: r1197896 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math/random/AbstractWell.java
main/java/org/apache/commons/math/random/MersenneTwister.java
site/xdoc/changes.xml
Author: psteitz
Date: Sat Nov 5 06:48:12 2011
New Revision: 1197896
URL: http://svn.apache.org/viewvc?rev=1197896&view=rev
Log:
Changed default seeding for MersenneTwister, WELL generators to add system identity hash code. JIRA: MATH-701.
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/AbstractWell.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/MersenneTwister.java
commons/proper/math/trunk/src/site/xdoc/changes.xml
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/AbstractWell.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/AbstractWell.java?rev=1197896&r1=1197895&r2=1197896&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/AbstractWell.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/AbstractWell.java Sat Nov 5 06:48:12 2011
@@ -61,15 +61,15 @@ public abstract class AbstractWell exten
protected final int[] i3;
/** Creates a new random number generator.
- * <p>The instance is initialized using the current time as the
- * seed.</p>
+ * <p>The instance is initialized using the current time plus the
+ * system identity hash code of this instance as the seed.</p>
* @param k number of bits in the pool (not necessarily a multiple of 32)
* @param m1 first parameter of the algorithm
* @param m2 second parameter of the algorithm
* @param m3 third parameter of the algorithm
*/
protected AbstractWell(final int k, final int m1, final int m2, final int m3) {
- this(k, m1, m2, m3, System.currentTimeMillis());
+ this(k, m1, m2, m3, null);
}
/** Creates a new random number generator using a single int seed.
@@ -145,14 +145,15 @@ public abstract class AbstractWell exten
/** Reinitialize the generator as if just built with the given int array seed.
* <p>The state of the generator is exactly the same as a new
* generator built with the same seed.</p>
- * @param seed the initial seed (32 bits integers array), if null
- * the seed of the generator will be related to the current time
+ * @param seed the initial seed (32 bits integers array). If null
+ * the seed of the generator will be the system time plus the system identity
+ * hash code of the instance.
*/
@Override
public void setSeed(final int[] seed) {
if (seed == null) {
- setSeed(System.currentTimeMillis());
+ setSeed(System.currentTimeMillis() + System.identityHashCode(this));
return;
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/MersenneTwister.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/MersenneTwister.java?rev=1197896&r1=1197895&r2=1197896&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/MersenneTwister.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/MersenneTwister.java Sat Nov 5 06:48:12 2011
@@ -100,12 +100,12 @@ public class MersenneTwister extends Bit
private int mti;
/** Creates a new random number generator.
- * <p>The instance is initialized using the current time as the
- * seed.</p>
+ * <p>The instance is initialized using the current time plus the
+ * system identity hash code of this instance as the seed.</p>
*/
public MersenneTwister() {
mt = new int[N];
- setSeed(System.currentTimeMillis());
+ setSeed(System.currentTimeMillis() + System.identityHashCode(this));
}
/** Creates a new random number generator using a single int seed.
@@ -156,13 +156,14 @@ public class MersenneTwister extends Bit
* <p>The state of the generator is exactly the same as a new
* generator built with the same seed.</p>
* @param seed the initial seed (32 bits integers array), if null
- * the seed of the generator will be related to the current time
+ * the seed of the generator will be the current system time plus the
+ * system identity hash code of this instance
*/
@Override
public void setSeed(int[] seed) {
if (seed == null) {
- setSeed(System.currentTimeMillis());
+ setSeed(System.currentTimeMillis() + System.identityHashCode(this));
return;
}
Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1197896&r1=1197895&r2=1197896&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Sat Nov 5 06:48:12 2011
@@ -52,6 +52,13 @@ The <action> type attribute can be add,u
If the output is not quite correct, check for invisible trailing spaces!
-->
<release version="3.0" date="TBD" description="TBD">
+ <action dev="psteitz" type="update" issue="MATH-701">
+ Changed the default seed used for RandomDataImpl, AbstractWell and MersenneTwister
+ PRNGs to add the system identity hash code of the instance to the current system
+ time, so generators initialized with default seeds within system clock resolution
+ will generate different sequences. Changed the default non-secure generator used
+ by RandomDataImpl to Well19937c.
+ </action>
<action dev="luc" type="fix" issue="MATH-695">
Fixed an event resetting issue in ODE.
</action>