On 11/4/11 10:50 AM, sebb wrote:
> On 4 November 2011 17:44, Phil Steitz <phil.ste...@gmail.com> wrote:
>> On 11/4/11 10:25 AM, sebb wrote:
>>> On 4 November 2011 16:20,  <pste...@apache.org> wrote:
>>>> Author: psteitz
>>>> Date: Fri Nov  4 16:20:05 2011
>>>> New Revision: 1197626
>>>>
>>>> URL: http://svn.apache.org/viewvc?rev=1197626&view=rev
>>>> Log:
>>>> Changed default non-secure generator to Well19937c and changed default 
>>>> seeds to add system identity haschode to timestamp.  JIRA: MATH-701.
>>> You've actually use the object hashcode - did you mean to use
>>> j.l.System.indentityHashcode() ?
>> Yes, maybe I am wrong, but I thought that's what you got by default
>> when hashcode is not overridden.  What we want is just something
>> that will be unique by instance (with high probability) and is
>> relatively fast to compute.
> Yes, you do get that if it is not overridden, but if the hashcode is
> later overriden then:
> - the Javadoc will not be accurate
> - it may not be as quick to compute.
>
> It would be easy to overlook this in a future update, so I'd recommend
> using what the Javadoc says.

Thanks for reviewing this.  Fixed in r1197716.

Phil
>
>> Phil
>>>> Modified:
>>>>    
>>>> commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java
>>>>
>>>> Modified: 
>>>> commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java
>>>> URL: 
>>>> http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java?rev=1197626&r1=1197625&r2=1197626&view=diff
>>>> ==============================================================================
>>>> --- 
>>>> commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java
>>>>  (original)
>>>> +++ 
>>>> commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java
>>>>  Fri Nov  4 16:20:05 2011
>>>> @@ -49,7 +49,7 @@ import org.apache.commons.math.util.Resi
>>>>  * instance to generate non-secure data and a {@link 
>>>> java.security.SecureRandom}
>>>>  * instance to provide data for the <code>nextSecureXxx</code> methods. If 
>>>> no
>>>>  * <code>RandomGenerator</code> is provided in the constructor, the 
>>>> default is
>>>> - * to use a generator based on {@link java.util.Random}. To plug in a 
>>>> different
>>>> + * to use a {@link Well19937c} generator. To plug in a different
>>>>  * implementation, either implement <code>RandomGenerator</code> directly 
>>>> or
>>>>  * extend {@link AbstractRandomGenerator}.
>>>>  * <p>
>>>> @@ -81,10 +81,10 @@ import org.apache.commons.math.util.Resi
>>>>  * When a new <code>RandomDataImpl</code> is created, the underlying random
>>>>  * number generators are <strong>not</strong> initialized. If you do not
>>>>  * explicitly seed the default non-secure generator, it is seeded with the
>>>> - * current time in milliseconds on first use. The same holds for the 
>>>> secure
>>>> - * generator. If you provide a <code>RandomGenerator</code> to the 
>>>> constructor,
>>>> - * however, this generator is not reseeded by the constructor nor is it 
>>>> reseeded
>>>> - * on first use.</li>
>>>> + * current time in milliseconds plus the system identity hash code on 
>>>> first use.
>>>> + * The same holds for the secure generator. If you provide a 
>>>> <code>RandomGenerator</code>
>>>> + * to the constructor, however, this generator is not reseeded by the 
>>>> constructor
>>>> + * nor is it reseeded on first use.</li>
>>>>  * <li>
>>>>  * The <code>reSeed</code> and <code>reSeedSecure</code> methods delegate 
>>>> to the
>>>>  * corresponding methods on the underlying <code>RandomGenerator</code> and
>>>> @@ -827,7 +827,8 @@ public class RandomDataImpl implements R
>>>>     /**
>>>>      * Returns the RandomGenerator used to generate non-secure random data.
>>>>      * <p>
>>>> -     * Creates and initializes a default generator if null.
>>>> +     * Creates and initializes a default generator if null. Uses a {@link 
>>>> Well19937c}
>>>> +     * generator with {@code System.currentTimeMillis() + hashCode()} as 
>>>> the default seed.
>>>>      * </p>
>>>>      *
>>>>      * @return the Random used to generate random data
>>>> @@ -835,8 +836,7 @@ public class RandomDataImpl implements R
>>>>      */
>>>>     private RandomGenerator getRan() {
>>>>         if (rand == null) {
>>>> -            rand = new JDKRandomGenerator();
>>>> -            rand.setSeed(System.currentTimeMillis());
>>>> +            rand = new Well19937c(System.currentTimeMillis() + 
>>>> hashCode());
>>>>         }
>>>>         return rand;
>>>>     }
>>>> @@ -844,7 +844,8 @@ public class RandomDataImpl implements R
>>>>     /**
>>>>      * Returns the SecureRandom used to generate secure random data.
>>>>      * <p>
>>>> -     * Creates and initializes if null.
>>>> +     * Creates and initializes if null.  Uses
>>>> +     * {@code System.currentTimeMillis() + hashCode()} as the default 
>>>> seed.
>>>>      * </p>
>>>>      *
>>>>      * @return the SecureRandom used to generate secure random data
>>>> @@ -852,7 +853,7 @@ public class RandomDataImpl implements R
>>>>     private SecureRandom getSecRan() {
>>>>         if (secRand == null) {
>>>>             secRand = new SecureRandom();
>>>> -            secRand.setSeed(System.currentTimeMillis());
>>>> +            secRand.setSeed(System.currentTimeMillis() + hashCode());
>>>>         }
>>>>         return secRand;
>>>>     }
>>>>
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
>>> For additional commands, e-mail: dev-h...@commons.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
>> For additional commands, e-mail: dev-h...@commons.apache.org
>>
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
> For additional commands, e-mail: dev-h...@commons.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to