commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gilles (Issue Comment Edited) (JIRA)" <j...@apache.org>
Subject [jira] [Issue Comment Edited] (MATH-701) Seeding a default RNG
Date Fri, 04 Nov 2011 13:01:00 GMT

    [ https://issues.apache.org/jira/browse/MATH-701?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13143944#comment-13143944
] 

Gilles edited comment on MATH-701 at 11/4/11 1:00 PM:
------------------------------------------------------

* From Harmony's implementation of "java.util.Random":
{code}
public Random() {
    setSeed(System.currentTimeMillis() + hashCode());
}
{code}

* I'd also prefer setting both RNGs at construction.
A user would have to write
{code}
SecureRandom secRand = SecureRandom.getInstance(algorithm, provider);
{code}
in his application's code, and that would make it clearer for him why and how an exception
can be generated (and that CM's code is not the cause of it).

* I also favour a new "SecureRandomDataImpl" as a subclass of "RandomDataImpl"; the constructor
would be something like:
{code}
public SecureRandomDataImpl(SecureRandom rng) {
    super(rng);
}
{code}
This would ensure that _all_ the {{next...}} methods use a secure RNG, whereas currently only
some of the accessors have a secure alternative (e.g. "nextGaussian" is not using "secRand").
This would be less confusing without requiring long explanations...

                
      was (Author: erans):
    * Harmony:
{code}
seed = System.currentTimeMillis() + hashCode();
{code}

* I'd also prefer setting both RNGs at construction.
A user would have to write
{code}
SecureRandom secRand = SecureRandom.getInstance(algorithm, provider);
{code}
in his application's code, and that would make it clearer for him why and how an exception
can be generated (and that CM's code is not the cause of it).

* I also favour a new "SecureRandomDataImpl" as a subclass of "RandomDataImpl"; the constructor
would be something like:
{code}
public SecureRandomDataImpl(SecureRandom rng) {
    super(rng);
}
{code}
This would ensure that _all_ the {{next...}} methods use a secure RNG, whereas currently only
some of the accessors have a secure alternative (e.g. "nextGaussian" is not using "secRand").
This would be less confusing without requiring long explanations...

                  
> Seeding a default RNG
> ---------------------
>
>                 Key: MATH-701
>                 URL: https://issues.apache.org/jira/browse/MATH-701
>             Project: Commons Math
>          Issue Type: Bug
>            Reporter: Gilles
>            Assignee: Gilles
>             Fix For: 3.0
>
>
> In "RandomDataImpl":
> {code}
> private RandomGenerator getRan() {
>     if (rand == null) {
>         rand = new JDKRandomGenerator();
>         rand.setSeed(System.currentTimeMillis());
>     }
>     return rand;
> }
> {code}
> The conditional branch is used by "sample()" in "AbstractContinuousDistribution".
> When several "...Distribution" objects are instantiated in a short time interval, they
are seeded with the same value.

--
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

        

Mime
View raw message