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

Gilles commented on MATH-899:
-----------------------------

Actually, it was Thomas's suggestion that we could provide an implementation of 
"RandomGenerator" that, IIUC, would wrap another instance and override all the 
methods with the "synchronized" keyword.
{code}
/**
 * Any "RandomGenerator" can be thread-safe if it is used through
 * an instance of this class.
 */
public class SynchronizedRandomGenerator {
  private final RandomGenerator wrapped;

  /**
   * @param rng Generator whose methods will be called through
   * their corresponding overridden synchronized version.
   * To ensure thread-safety, the wrapped generator <em>must</em>
   * not be used directly.
   */
  public SynchronizedRandomGenerator(RandomGenerator rng) {
    wrapped = rng;
  }

  public synchronized void setSeed(int seed) {
    wrapped.setSeed(seed);
  }

  // [Similarly for all methods.]
}
{code}

Any caveat with that solution?

                
> A random crash of MersenneTwister random generator
> --------------------------------------------------
>
>                 Key: MATH-899
>                 URL: https://issues.apache.org/jira/browse/MATH-899
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.0
>         Environment: Windows 7, JDK 1.7.05
>            Reporter: Alexander Nozik
>            Priority: Minor
>
> There is a very small probability that MersenneTwister generator gives a 
> following error: 
> java.lang.ArrayIndexOutOfBoundsException: 624
> in MersenneTwister.java line 253
> The error is completely random and its probability is about 1e-8.
> UPD: The problem most probably arises only in multy-thread mode.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to