Merge branch 'task-MATH-1366' into develop
Completes the following issues (see JIRA): MATH-1366 MATH-1341 MATH-1363 MATH-1346 MATH-1369
This commit is contained in:
commit
595f3fb79a
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.commons.math4.random;
|
||||
package org.apache.commons.math4.distribution;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
|
@ -28,10 +28,6 @@ import java.nio.charset.Charset;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.math4.distribution.AbstractRealDistribution;
|
||||
import org.apache.commons.math4.distribution.ConstantRealDistribution;
|
||||
import org.apache.commons.math4.distribution.NormalDistribution;
|
||||
import org.apache.commons.math4.distribution.RealDistribution;
|
||||
import org.apache.commons.math4.exception.MathIllegalStateException;
|
||||
import org.apache.commons.math4.exception.MathInternalError;
|
||||
import org.apache.commons.math4.exception.NullArgumentException;
|
||||
|
@ -46,7 +42,7 @@ import org.apache.commons.math4.util.FastMath;
|
|||
import org.apache.commons.math4.util.MathUtils;
|
||||
|
||||
/**
|
||||
* <p>Represents an <a href="http://http://en.wikipedia.org/wiki/Empirical_distribution_function">
|
||||
* <p>Represents an <a href="http://en.wikipedia.org/wiki/Empirical_distribution_function">
|
||||
* empirical probability distribution</a> -- a probability distribution derived
|
||||
* from observed data without making any assumptions about the functional form
|
||||
* of the population distribution that the data come from.</p>
|
|
@ -1,294 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
|
||||
/**
|
||||
* Abstract class implementing the {@link RandomGenerator} interface.
|
||||
* Default implementations for all methods other than {@link #nextDouble()} and
|
||||
* {@link #setSeed(long)} are provided.
|
||||
* <p>
|
||||
* All data generation methods are based on {@code code nextDouble()}.
|
||||
* Concrete implementations <strong>must</strong> override
|
||||
* this method and <strong>should</strong> provide better / more
|
||||
* performant implementations of the other methods if the underlying PRNG
|
||||
* supplies them.</p>
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
public abstract class AbstractRandomGenerator implements RandomGenerator {
|
||||
|
||||
/**
|
||||
* Cached random normal value. The default implementation for
|
||||
* {@link #nextGaussian} generates pairs of values and this field caches the
|
||||
* second value so that the full algorithm is not executed for every
|
||||
* activation. The value {@code Double.NaN} signals that there is
|
||||
* no cached value. Use {@link #clear} to clear the cached value.
|
||||
*/
|
||||
private double cachedNormalDeviate = Double.NaN;
|
||||
|
||||
/**
|
||||
* Construct a RandomGenerator.
|
||||
*/
|
||||
public AbstractRandomGenerator() {
|
||||
super();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the cache used by the default implementation of
|
||||
* {@link #nextGaussian}. Implementations that do not override the
|
||||
* default implementation of {@code nextGaussian} should call this
|
||||
* method in the implementation of {@link #setSeed(long)}
|
||||
*/
|
||||
public void clear() {
|
||||
cachedNormalDeviate = Double.NaN;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void setSeed(int seed) {
|
||||
setSeed((long) seed);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void setSeed(int[] seed) {
|
||||
// the following number is the largest prime that fits in 32 bits (it is 2^32 - 5)
|
||||
final long prime = 4294967291l;
|
||||
|
||||
long combined = 0l;
|
||||
for (int s : seed) {
|
||||
combined = combined * prime + s;
|
||||
}
|
||||
setSeed(combined);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the seed of the underlying random number generator using a
|
||||
* {@code long} seed. Sequences of values generated starting with the
|
||||
* same seeds should be identical.
|
||||
* <p>
|
||||
* Implementations that do not override the default implementation of
|
||||
* {@code nextGaussian} should include a call to {@link #clear} in the
|
||||
* implementation of this method.</p>
|
||||
*
|
||||
* @param seed the seed value
|
||||
*/
|
||||
@Override
|
||||
public abstract void setSeed(long seed);
|
||||
|
||||
/**
|
||||
* Generates random bytes and places them into a user-supplied
|
||||
* byte array. The number of random bytes produced is equal to
|
||||
* the length of the byte array.
|
||||
* <p>
|
||||
* The default implementation fills the array with bytes extracted from
|
||||
* random integers generated using {@link #nextInt}.</p>
|
||||
*
|
||||
* @param bytes the non-null byte array in which to put the
|
||||
* random bytes
|
||||
*/
|
||||
@Override
|
||||
public void nextBytes(byte[] bytes) {
|
||||
// Multiple 4 part of length (i.e. length with two least significant bits unset).
|
||||
final int max = bytes.length & 0x7ffffffc;
|
||||
|
||||
int index = 0;
|
||||
// Start filling in the byte array, 4 bytes at a time.
|
||||
while (index < max) {
|
||||
final int random = nextInt();
|
||||
bytes[index++] = (byte) random;
|
||||
bytes[index++] = (byte) (random >>> 8);
|
||||
bytes[index++] = (byte) (random >>> 16);
|
||||
bytes[index++] = (byte) (random >>> 24);
|
||||
}
|
||||
|
||||
// Fill in the remaining bytes.
|
||||
if (index < bytes.length) {
|
||||
int random = nextInt();
|
||||
while (true) {
|
||||
bytes[index++] = (byte) random;
|
||||
if (index < bytes.length) {
|
||||
random >>>= 8;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next pseudorandom, uniformly distributed {@code int}
|
||||
* value from this random number generator's sequence.
|
||||
* All 2<font size="-1"><sup>32</sup></font> possible {@code int} values
|
||||
* should be produced with (approximately) equal probability.
|
||||
* <p>
|
||||
* The default implementation provided here returns
|
||||
* <pre>
|
||||
* <code>(int) (nextDouble() * Integer.MAX_VALUE)</code>
|
||||
* </pre></p>
|
||||
*
|
||||
* @return the next pseudorandom, uniformly distributed {@code int}
|
||||
* value from this random number generator's sequence
|
||||
*/
|
||||
@Override
|
||||
public int nextInt() {
|
||||
return (int) ((2d * nextDouble() - 1d) * Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pseudorandom, uniformly distributed {@code int} value
|
||||
* between 0 (inclusive) and the specified value (exclusive), drawn from
|
||||
* this random number generator's sequence.
|
||||
* <p>
|
||||
* The default implementation returns
|
||||
* <pre>
|
||||
* <code>(int) (nextDouble() * n</code>
|
||||
* </pre></p>
|
||||
*
|
||||
* @param n the bound on the random number to be returned. Must be
|
||||
* positive.
|
||||
* @return a pseudorandom, uniformly distributed {@code int}
|
||||
* value between 0 (inclusive) and n (exclusive).
|
||||
* @throws NotStrictlyPositiveException if {@code n <= 0}.
|
||||
*/
|
||||
@Override
|
||||
public int nextInt(int n) {
|
||||
if (n <= 0 ) {
|
||||
throw new NotStrictlyPositiveException(n);
|
||||
}
|
||||
int result = (int) (nextDouble() * n);
|
||||
return result < n ? result : n - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next pseudorandom, uniformly distributed {@code long}
|
||||
* value from this random number generator's sequence. All
|
||||
* 2<font size="-1"><sup>64</sup></font> possible {@code long} values
|
||||
* should be produced with (approximately) equal probability.
|
||||
* <p>
|
||||
* The default implementation returns
|
||||
* <pre>
|
||||
* <code>(long) (nextDouble() * Long.MAX_VALUE)</code>
|
||||
* </pre></p>
|
||||
*
|
||||
* @return the next pseudorandom, uniformly distributed {@code long}
|
||||
*value from this random number generator's sequence
|
||||
*/
|
||||
@Override
|
||||
public long nextLong() {
|
||||
return (long) ((2d * nextDouble() - 1d) * Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next pseudorandom, uniformly distributed
|
||||
* {@code boolean} value from this random number generator's
|
||||
* sequence.
|
||||
* <p>
|
||||
* The default implementation returns
|
||||
* <pre>
|
||||
* <code>nextDouble() <= 0.5</code>
|
||||
* </pre></p>
|
||||
*
|
||||
* @return the next pseudorandom, uniformly distributed
|
||||
* {@code boolean} value from this random number generator's
|
||||
* sequence
|
||||
*/
|
||||
@Override
|
||||
public boolean nextBoolean() {
|
||||
return nextDouble() <= 0.5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next pseudorandom, uniformly distributed {@code float}
|
||||
* value between {@code 0.0} and {@code 1.0} from this random
|
||||
* number generator's sequence.
|
||||
* <p>
|
||||
* The default implementation returns
|
||||
* <pre>
|
||||
* <code>(float) nextDouble() </code>
|
||||
* </pre></p>
|
||||
*
|
||||
* @return the next pseudorandom, uniformly distributed {@code float}
|
||||
* value between {@code 0.0} and {@code 1.0} from this
|
||||
* random number generator's sequence
|
||||
*/
|
||||
@Override
|
||||
public float nextFloat() {
|
||||
return (float) nextDouble();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next pseudorandom, uniformly distributed
|
||||
* {@code double} value between {@code 0.0} and
|
||||
* {@code 1.0} from this random number generator's sequence.
|
||||
* <p>
|
||||
* This method provides the underlying source of random data used by the
|
||||
* other methods.</p>
|
||||
*
|
||||
* @return the next pseudorandom, uniformly distributed
|
||||
* {@code double} value between {@code 0.0} and
|
||||
* {@code 1.0} from this random number generator's sequence
|
||||
*/
|
||||
@Override
|
||||
public abstract double nextDouble();
|
||||
|
||||
/**
|
||||
* Returns the next pseudorandom, Gaussian ("normally") distributed
|
||||
* {@code double} value with mean {@code 0.0} and standard
|
||||
* deviation {@code 1.0} from this random number generator's sequence.
|
||||
* <p>
|
||||
* The default implementation uses the <em>Polar Method</em>
|
||||
* due to G.E.P. Box, M.E. Muller and G. Marsaglia, as described in
|
||||
* D. Knuth, <u>The Art of Computer Programming</u>, 3.4.1C.</p>
|
||||
* <p>
|
||||
* The algorithm generates a pair of independent random values. One of
|
||||
* these is cached for reuse, so the full algorithm is not executed on each
|
||||
* activation. Implementations that do not override this method should
|
||||
* make sure to call {@link #clear} to clear the cached value in the
|
||||
* implementation of {@link #setSeed(long)}.</p>
|
||||
*
|
||||
* @return the next pseudorandom, Gaussian ("normally") distributed
|
||||
* {@code double} value with mean {@code 0.0} and
|
||||
* standard deviation {@code 1.0} from this random number
|
||||
* generator's sequence
|
||||
*/
|
||||
@Override
|
||||
public double nextGaussian() {
|
||||
if (!Double.isNaN(cachedNormalDeviate)) {
|
||||
double dev = cachedNormalDeviate;
|
||||
cachedNormalDeviate = Double.NaN;
|
||||
return dev;
|
||||
}
|
||||
double v1 = 0;
|
||||
double v2 = 0;
|
||||
double s = 1;
|
||||
while (s >=1 ) {
|
||||
v1 = 2 * nextDouble() - 1;
|
||||
v2 = 2 * nextDouble() - 1;
|
||||
s = v1 * v1 + v2 * v2;
|
||||
}
|
||||
if (s != 0) {
|
||||
s = FastMath.sqrt(-2 * FastMath.log(s) / s);
|
||||
}
|
||||
cachedNormalDeviate = v2 * s;
|
||||
return v1 * s;
|
||||
}
|
||||
}
|
|
@ -1,246 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
|
||||
|
||||
/** This abstract class implements the WELL class of pseudo-random number generator
|
||||
* from François Panneton, Pierre L'Ecuyer and Makoto Matsumoto.
|
||||
* <p>
|
||||
* This generator is described in a paper by François Panneton,
|
||||
* Pierre L'Ecuyer and Makoto Matsumoto <a
|
||||
* href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng.pdf">Improved
|
||||
* Long-Period Generators Based on Linear Recurrences Modulo 2</a> ACM
|
||||
* Transactions on Mathematical Software, 32, 1 (2006). The errata for the paper
|
||||
* are in <a href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng-errata.txt">wellrng-errata.txt</a>.</p>
|
||||
*
|
||||
* @see <a href="http://www.iro.umontreal.ca/~panneton/WELLRNG.html">WELL Random number generator</a>
|
||||
* @since 2.2
|
||||
*/
|
||||
public abstract class AbstractWell extends BitsStreamGenerator implements Serializable {
|
||||
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 20150223L;
|
||||
|
||||
/** Current index in the bytes pool. */
|
||||
protected int index;
|
||||
|
||||
/** Bytes pool. */
|
||||
protected final int[] v;
|
||||
|
||||
/** Creates a new random number generator.
|
||||
* <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)
|
||||
*/
|
||||
protected AbstractWell(final int k) {
|
||||
this(k, null);
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using a single int seed.
|
||||
* @param k number of bits in the pool (not necessarily a multiple of 32)
|
||||
* @param seed the initial seed (32 bits integer)
|
||||
*/
|
||||
protected AbstractWell(final int k, final int seed) {
|
||||
this(k, new int[] { seed });
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using an int array seed.
|
||||
* @param k number of bits in the pool (not necessarily a multiple of 32)
|
||||
* @param seed the initial seed (32 bits integers array), if null
|
||||
* the seed of the generator will be related to the current time
|
||||
*/
|
||||
protected AbstractWell(final int k, final int[] seed) {
|
||||
|
||||
final int r = calculateBlockCount(k);
|
||||
this.v = new int[r];
|
||||
this.index = 0;
|
||||
|
||||
// initialize the pool content
|
||||
setSeed(seed);
|
||||
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using a single long seed.
|
||||
* @param k number of bits in the pool (not necessarily a multiple of 32)
|
||||
* @param seed the initial seed (64 bits integer)
|
||||
*/
|
||||
protected AbstractWell(final int k, final long seed) {
|
||||
this(k, new int[] { (int) (seed >>> 32), (int) (seed & 0xffffffffl) });
|
||||
}
|
||||
|
||||
/** Reinitialize the generator as if just built with the given int 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 integer)
|
||||
*/
|
||||
@Override
|
||||
public void setSeed(final int seed) {
|
||||
setSeed(new int[] { seed });
|
||||
}
|
||||
|
||||
/** 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 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() + System.identityHashCode(this));
|
||||
return;
|
||||
}
|
||||
|
||||
System.arraycopy(seed, 0, v, 0, FastMath.min(seed.length, v.length));
|
||||
|
||||
if (seed.length < v.length) {
|
||||
for (int i = seed.length; i < v.length; ++i) {
|
||||
final long l = v[i - seed.length];
|
||||
v[i] = (int) ((1812433253l * (l ^ (l >> 30)) + i) & 0xffffffffL);
|
||||
}
|
||||
}
|
||||
|
||||
index = 0;
|
||||
clear(); // Clear normal deviate cache
|
||||
}
|
||||
|
||||
/** Reinitialize the generator as if just built with the given long 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 (64 bits integer)
|
||||
*/
|
||||
@Override
|
||||
public void setSeed(final long seed) {
|
||||
setSeed(new int[] { (int) (seed >>> 32), (int) (seed & 0xffffffffl) });
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected abstract int next(final int bits);
|
||||
|
||||
/** Calculate the number of 32-bits blocks.
|
||||
* @param k number of bits in the pool (not necessarily a multiple of 32)
|
||||
* @return the number of 32-bits blocks
|
||||
*/
|
||||
private static int calculateBlockCount(final int k) {
|
||||
// the bits pool contains k bits, k = r w - p where r is the number
|
||||
// of w bits blocks, w is the block size (always 32 in the original paper)
|
||||
// and p is the number of unused bits in the last block
|
||||
final int w = 32;
|
||||
final int r = (k + w - 1) / w;
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inner class used to store the indirection index table which is fixed for a given type of WELL class
|
||||
* of pseudo-random number generator.
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
protected static final class IndexTable {
|
||||
/** Index indirection table giving for each index its predecessor taking table size into account. */
|
||||
private final int[] iRm1;
|
||||
|
||||
/** Index indirection table giving for each index its second predecessor taking table size into account. */
|
||||
private final int[] iRm2;
|
||||
|
||||
/** Index indirection table giving for each index the value index + m1 taking table size into account. */
|
||||
private final int[] i1;
|
||||
|
||||
/** Index indirection table giving for each index the value index + m2 taking table size into account. */
|
||||
private final int[] i2;
|
||||
|
||||
/** Index indirection table giving for each index the value index + m3 taking table size into account. */
|
||||
private final int[] i3;
|
||||
|
||||
/** Creates a new pre-calculated indirection index table.
|
||||
* @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
|
||||
*/
|
||||
public IndexTable(final int k, final int m1, final int m2, final int m3) {
|
||||
|
||||
final int r = calculateBlockCount(k);
|
||||
|
||||
// precompute indirection index tables. These tables are used for optimizing access
|
||||
// they allow saving computations like "(j + r - 2) % r" with costly modulo operations
|
||||
iRm1 = new int[r];
|
||||
iRm2 = new int[r];
|
||||
i1 = new int[r];
|
||||
i2 = new int[r];
|
||||
i3 = new int[r];
|
||||
for (int j = 0; j < r; ++j) {
|
||||
iRm1[j] = (j + r - 1) % r;
|
||||
iRm2[j] = (j + r - 2) % r;
|
||||
i1[j] = (j + m1) % r;
|
||||
i2[j] = (j + m2) % r;
|
||||
i3[j] = (j + m3) % r;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the predecessor of the given index modulo the table size.
|
||||
* @param index the index to look at
|
||||
* @return (index - 1) % table size
|
||||
*/
|
||||
public int getIndexPred(final int index) {
|
||||
return iRm1[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the second predecessor of the given index modulo the table size.
|
||||
* @param index the index to look at
|
||||
* @return (index - 2) % table size
|
||||
*/
|
||||
public int getIndexPred2(final int index) {
|
||||
return iRm2[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns index + M1 modulo the table size.
|
||||
* @param index the index to look at
|
||||
* @return (index + M1) % table size
|
||||
*/
|
||||
public int getIndexM1(final int index) {
|
||||
return i1[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns index + M2 modulo the table size.
|
||||
* @param index the index to look at
|
||||
* @return (index + M2) % table size
|
||||
*/
|
||||
public int getIndexM2(final int index) {
|
||||
return i2[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns index + M3 modulo the table size.
|
||||
* @param index the index to look at
|
||||
* @return (index + M3) % table size
|
||||
*/
|
||||
public int getIndexM3(final int index) {
|
||||
return i3[index];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,218 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
|
||||
/** Base class for random number generators that generates bits streams.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public abstract class BitsStreamGenerator
|
||||
implements RandomGenerator,
|
||||
Serializable {
|
||||
/** Serializable version identifier */
|
||||
private static final long serialVersionUID = 20130104L;
|
||||
/** Next gaussian. */
|
||||
private double nextGaussian;
|
||||
|
||||
/**
|
||||
* Creates a new random number generator.
|
||||
*/
|
||||
public BitsStreamGenerator() {
|
||||
nextGaussian = Double.NaN;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public abstract void setSeed(int seed);
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public abstract void setSeed(int[] seed);
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public abstract void setSeed(long seed);
|
||||
|
||||
/** Generate next pseudorandom number.
|
||||
* <p>This method is the core generation algorithm. It is used by all the
|
||||
* public generation methods for the various primitive types {@link
|
||||
* #nextBoolean()}, {@link #nextBytes(byte[])}, {@link #nextDouble()},
|
||||
* {@link #nextFloat()}, {@link #nextGaussian()}, {@link #nextInt()},
|
||||
* {@link #next(int)} and {@link #nextLong()}.</p>
|
||||
* @param bits number of random bits to produce
|
||||
* @return random bits generated
|
||||
*/
|
||||
protected abstract int next(int bits);
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public boolean nextBoolean() {
|
||||
return next(1) != 0;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void nextBytes(byte[] bytes) {
|
||||
// Multiple 4 part of length (i.e. length with two least significant bits unset).
|
||||
final int max = bytes.length & 0x7ffffffc;
|
||||
|
||||
int index = 0;
|
||||
// Start filling in the byte array, 4 bytes at a time.
|
||||
while (index < max) {
|
||||
final int random = next(32);
|
||||
bytes[index++] = (byte) random;
|
||||
bytes[index++] = (byte) (random >>> 8);
|
||||
bytes[index++] = (byte) (random >>> 16);
|
||||
bytes[index++] = (byte) (random >>> 24);
|
||||
}
|
||||
|
||||
// Fill in the remaing bytes.
|
||||
if (index < bytes.length) {
|
||||
int random = next(32);
|
||||
while (true) {
|
||||
bytes[index++] = (byte) random;
|
||||
if (index < bytes.length) {
|
||||
random >>>= 8;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public double nextDouble() {
|
||||
final long high = ((long) next(26)) << 26;
|
||||
final int low = next(26);
|
||||
return (high | low) * 0x1.0p-52d;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public float nextFloat() {
|
||||
return next(23) * 0x1.0p-23f;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public double nextGaussian() {
|
||||
|
||||
final double random;
|
||||
if (Double.isNaN(nextGaussian)) {
|
||||
// generate a new pair of gaussian numbers
|
||||
final double x = nextDouble();
|
||||
final double y = nextDouble();
|
||||
final double alpha = 2 * FastMath.PI * x;
|
||||
final double r = FastMath.sqrt(-2 * FastMath.log(y));
|
||||
random = r * FastMath.cos(alpha);
|
||||
nextGaussian = r * FastMath.sin(alpha);
|
||||
} else {
|
||||
// use the second element of the pair already generated
|
||||
random = nextGaussian;
|
||||
nextGaussian = Double.NaN;
|
||||
}
|
||||
|
||||
return random;
|
||||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public int nextInt() {
|
||||
return next(32);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>This default implementation is copied from Apache Harmony
|
||||
* java.util.Random (r929253).</p>
|
||||
*
|
||||
* <p>Implementation notes: <ul>
|
||||
* <li>If n is a power of 2, this method returns
|
||||
* {@code (int) ((n * (long) next(31)) >> 31)}.</li>
|
||||
*
|
||||
* <li>If n is not a power of 2, what is returned is {@code next(31) % n}
|
||||
* with {@code next(31)} values rejected (i.e. regenerated) until a
|
||||
* value that is larger than the remainder of {@code Integer.MAX_VALUE / n}
|
||||
* is generated. Rejection of this initial segment is necessary to ensure
|
||||
* a uniform distribution.</li></ul></p>
|
||||
*/
|
||||
@Override
|
||||
public int nextInt(int n) throws IllegalArgumentException {
|
||||
if (n > 0) {
|
||||
if ((n & -n) == n) {
|
||||
return (int) ((n * (long) next(31)) >> 31);
|
||||
}
|
||||
int bits;
|
||||
int val;
|
||||
do {
|
||||
bits = next(31);
|
||||
val = bits % n;
|
||||
} while (bits - val + (n - 1) < 0);
|
||||
return val;
|
||||
}
|
||||
throw new NotStrictlyPositiveException(n);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public long nextLong() {
|
||||
final long high = ((long) next(32)) << 32;
|
||||
final long low = (next(32)) & 0xffffffffL;
|
||||
return high | low;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pseudorandom, uniformly distributed {@code long} value
|
||||
* between 0 (inclusive) and the specified value (exclusive), drawn from
|
||||
* this random number generator's sequence.
|
||||
*
|
||||
* @param n the bound on the random number to be returned. Must be
|
||||
* positive.
|
||||
* @return a pseudorandom, uniformly distributed {@code long}
|
||||
* value between 0 (inclusive) and n (exclusive).
|
||||
* @throws IllegalArgumentException if n is not positive.
|
||||
*/
|
||||
public long nextLong(long n) throws IllegalArgumentException {
|
||||
if (n > 0) {
|
||||
long bits;
|
||||
long val;
|
||||
do {
|
||||
bits = ((long) next(31)) << 32;
|
||||
bits |= ((long) next(32)) & 0xffffffffL;
|
||||
val = bits % n;
|
||||
} while (bits - val + (n - 1) < 0);
|
||||
return val;
|
||||
}
|
||||
throw new NotStrictlyPositiveException(n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the cache used by the default implementation of
|
||||
* {@link #nextGaussian}.
|
||||
*/
|
||||
public void clear() {
|
||||
nextGaussian = Double.NaN;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,274 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
|
||||
/**
|
||||
* A fast cryptographic pseudo-random number generator.
|
||||
* <p>
|
||||
* ISAAC (Indirection, Shift, Accumulate, Add, and Count) generates 32-bit
|
||||
* random numbers.
|
||||
* ISAAC has been designed to be cryptographically secure and is inspired
|
||||
* by RC4.
|
||||
* Cycles are guaranteed to be at least 2<sup>40</sup> values long, and they
|
||||
* are 2<sup>8295</sup> values long on average.
|
||||
* The results are uniformly distributed, unbiased, and unpredictable unless
|
||||
* you know the seed.
|
||||
* <p>
|
||||
* This code is based (with minor changes and improvements) on the original
|
||||
* implementation of the algorithm by Bob Jenkins.
|
||||
*
|
||||
* @see <a href="http://burtleburtle.net/bob/rand/isaacafa.html">
|
||||
* ISAAC: a fast cryptographic pseudo-random number generator</a>
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
public class ISAACRandom extends BitsStreamGenerator implements Serializable {
|
||||
/** Serializable version identifier */
|
||||
private static final long serialVersionUID = 7288197941165002400L;
|
||||
/** Log of size of rsl[] and mem[] */
|
||||
private static final int SIZE_L = 8;
|
||||
/** Size of rsl[] and mem[] */
|
||||
private static final int SIZE = 1 << SIZE_L;
|
||||
/** Half-size of rsl[] and mem[] */
|
||||
private static final int H_SIZE = SIZE >> 1;
|
||||
/** For pseudo-random lookup */
|
||||
private static final int MASK = SIZE - 1 << 2;
|
||||
/** The golden ratio */
|
||||
private static final int GLD_RATIO = 0x9e3779b9;
|
||||
/** The results given to the user */
|
||||
private final int[] rsl = new int[SIZE];
|
||||
/** The internal state */
|
||||
private final int[] mem = new int[SIZE];
|
||||
/** Count through the results in rsl[] */
|
||||
private int count;
|
||||
/** Accumulator */
|
||||
private int isaacA;
|
||||
/** The last result */
|
||||
private int isaacB;
|
||||
/** Counter, guarantees cycle is at least 2^40 */
|
||||
private int isaacC;
|
||||
/** Service variable. */
|
||||
private final int[] arr = new int[8];
|
||||
/** Service variable. */
|
||||
private int isaacX;
|
||||
/** Service variable. */
|
||||
private int isaacI;
|
||||
/** Service variable. */
|
||||
private int isaacJ;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new ISAAC random number generator.
|
||||
* <br/>
|
||||
* The instance is initialized using a combination of the
|
||||
* current time and system hash code of the instance as the seed.
|
||||
*/
|
||||
public ISAACRandom() {
|
||||
setSeed(System.currentTimeMillis() + System.identityHashCode(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ISAAC random number generator using a single long seed.
|
||||
*
|
||||
* @param seed Initial seed.
|
||||
*/
|
||||
public ISAACRandom(long seed) {
|
||||
setSeed(seed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ISAAC random number generator using an int array seed.
|
||||
*
|
||||
* @param seed Initial seed. If {@code null}, the seed will be related
|
||||
* to the current time.
|
||||
*/
|
||||
public ISAACRandom(int[] seed) {
|
||||
setSeed(seed);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void setSeed(int seed) {
|
||||
setSeed(new int[]{seed});
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void setSeed(long seed) {
|
||||
setSeed(new int[]{(int) (seed >>> 32), (int) (seed & 0xffffffffL)});
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void setSeed(int[] seed) {
|
||||
if (seed == null) {
|
||||
setSeed(System.currentTimeMillis() + System.identityHashCode(this));
|
||||
return;
|
||||
}
|
||||
final int seedLen = seed.length;
|
||||
final int rslLen = rsl.length;
|
||||
System.arraycopy(seed, 0, rsl, 0, FastMath.min(seedLen, rslLen));
|
||||
if (seedLen < rslLen) {
|
||||
for (int j = seedLen; j < rslLen; j++) {
|
||||
long k = rsl[j - seedLen];
|
||||
rsl[j] = (int) (0x6c078965L * (k ^ k >> 30) + j & 0xffffffffL);
|
||||
}
|
||||
}
|
||||
initState();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected int next(int bits) {
|
||||
if (count < 0) {
|
||||
isaac();
|
||||
count = SIZE - 1;
|
||||
}
|
||||
return rsl[count--] >>> 32 - bits;
|
||||
}
|
||||
|
||||
/** Generate 256 results */
|
||||
private void isaac() {
|
||||
isaacI = 0;
|
||||
isaacJ = H_SIZE;
|
||||
isaacB += ++isaacC;
|
||||
while (isaacI < H_SIZE) {
|
||||
isaac2();
|
||||
}
|
||||
isaacJ = 0;
|
||||
while (isaacJ < H_SIZE) {
|
||||
isaac2();
|
||||
}
|
||||
}
|
||||
|
||||
/** Intermediate internal loop. */
|
||||
private void isaac2() {
|
||||
isaacX = mem[isaacI];
|
||||
isaacA ^= isaacA << 13;
|
||||
isaacA += mem[isaacJ++];
|
||||
isaac3();
|
||||
isaacX = mem[isaacI];
|
||||
isaacA ^= isaacA >>> 6;
|
||||
isaacA += mem[isaacJ++];
|
||||
isaac3();
|
||||
isaacX = mem[isaacI];
|
||||
isaacA ^= isaacA << 2;
|
||||
isaacA += mem[isaacJ++];
|
||||
isaac3();
|
||||
isaacX = mem[isaacI];
|
||||
isaacA ^= isaacA >>> 16;
|
||||
isaacA += mem[isaacJ++];
|
||||
isaac3();
|
||||
}
|
||||
|
||||
/** Lowest level internal loop. */
|
||||
private void isaac3() {
|
||||
mem[isaacI] = mem[(isaacX & MASK) >> 2] + isaacA + isaacB;
|
||||
isaacB = mem[(mem[isaacI] >> SIZE_L & MASK) >> 2] + isaacX;
|
||||
rsl[isaacI++] = isaacB;
|
||||
}
|
||||
|
||||
/** Initialize, or reinitialize, this instance of rand. */
|
||||
private void initState() {
|
||||
isaacA = 0;
|
||||
isaacB = 0;
|
||||
isaacC = 0;
|
||||
for (int j = 0; j < arr.length; j++) {
|
||||
arr[j] = GLD_RATIO;
|
||||
}
|
||||
for (int j = 0; j < 4; j++) {
|
||||
shuffle();
|
||||
}
|
||||
// fill in mem[] with messy stuff
|
||||
for (int j = 0; j < SIZE; j += 8) {
|
||||
arr[0] += rsl[j];
|
||||
arr[1] += rsl[j + 1];
|
||||
arr[2] += rsl[j + 2];
|
||||
arr[3] += rsl[j + 3];
|
||||
arr[4] += rsl[j + 4];
|
||||
arr[5] += rsl[j + 5];
|
||||
arr[6] += rsl[j + 6];
|
||||
arr[7] += rsl[j + 7];
|
||||
shuffle();
|
||||
setState(j);
|
||||
}
|
||||
// second pass makes all of seed affect all of mem
|
||||
for (int j = 0; j < SIZE; j += 8) {
|
||||
arr[0] += mem[j];
|
||||
arr[1] += mem[j + 1];
|
||||
arr[2] += mem[j + 2];
|
||||
arr[3] += mem[j + 3];
|
||||
arr[4] += mem[j + 4];
|
||||
arr[5] += mem[j + 5];
|
||||
arr[6] += mem[j + 6];
|
||||
arr[7] += mem[j + 7];
|
||||
shuffle();
|
||||
setState(j);
|
||||
}
|
||||
isaac();
|
||||
count = SIZE - 1;
|
||||
clear();
|
||||
}
|
||||
|
||||
/** Shuffle array. */
|
||||
private void shuffle() {
|
||||
arr[0] ^= arr[1] << 11;
|
||||
arr[3] += arr[0];
|
||||
arr[1] += arr[2];
|
||||
arr[1] ^= arr[2] >>> 2;
|
||||
arr[4] += arr[1];
|
||||
arr[2] += arr[3];
|
||||
arr[2] ^= arr[3] << 8;
|
||||
arr[5] += arr[2];
|
||||
arr[3] += arr[4];
|
||||
arr[3] ^= arr[4] >>> 16;
|
||||
arr[6] += arr[3];
|
||||
arr[4] += arr[5];
|
||||
arr[4] ^= arr[5] << 10;
|
||||
arr[7] += arr[4];
|
||||
arr[5] += arr[6];
|
||||
arr[5] ^= arr[6] >>> 4;
|
||||
arr[0] += arr[5];
|
||||
arr[6] += arr[7];
|
||||
arr[6] ^= arr[7] << 8;
|
||||
arr[1] += arr[6];
|
||||
arr[7] += arr[0];
|
||||
arr[7] ^= arr[0] >>> 9;
|
||||
arr[2] += arr[7];
|
||||
arr[0] += arr[1];
|
||||
}
|
||||
|
||||
/** Set the state by copying the internal arrays.
|
||||
*
|
||||
* @param start First index into {@link #mem} array.
|
||||
*/
|
||||
private void setState(int start) {
|
||||
mem[start] = arr[0];
|
||||
mem[start + 1] = arr[1];
|
||||
mem[start + 2] = arr[2];
|
||||
mem[start + 3] = arr[3];
|
||||
mem[start + 4] = arr[4];
|
||||
mem[start + 5] = arr[5];
|
||||
mem[start + 6] = arr[6];
|
||||
mem[start + 7] = arr[7];
|
||||
}
|
||||
}
|
|
@ -1,121 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import java.util.Random;
|
||||
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
||||
|
||||
/**
|
||||
* A {@link RandomGenerator} adapter that delegates the random number
|
||||
* generation to the standard {@link java.util.Random} class.
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
public class JDKRandomGenerator
|
||||
implements RandomGenerator {
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 20151227L;
|
||||
/** JDK's RNG. */
|
||||
private final Random delegate;
|
||||
|
||||
/**
|
||||
* Creates an instance with an arbitrary seed.
|
||||
*/
|
||||
public JDKRandomGenerator() {
|
||||
delegate = new Random();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance with the given seed.
|
||||
*
|
||||
* @param seed Initial seed.
|
||||
* @since 3.6
|
||||
*/
|
||||
public JDKRandomGenerator(long seed) {
|
||||
delegate = new Random(seed);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void setSeed(int seed) {
|
||||
delegate.setSeed((long) seed);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void setSeed(long seed) {
|
||||
delegate.setSeed( seed);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void setSeed(int[] seed) {
|
||||
delegate.setSeed(RandomGeneratorFactory.convertToLong(seed));
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void nextBytes(byte[] bytes) {
|
||||
delegate.nextBytes(bytes);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public int nextInt() {
|
||||
return delegate.nextInt();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public long nextLong() {
|
||||
return delegate.nextLong();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public boolean nextBoolean() {
|
||||
return delegate.nextBoolean();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public float nextFloat() {
|
||||
return delegate.nextFloat();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public double nextDouble() {
|
||||
return delegate.nextDouble();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public double nextGaussian() {
|
||||
return delegate.nextGaussian();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public int nextInt(int n) {
|
||||
try {
|
||||
return delegate.nextInt(n);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new NotStrictlyPositiveException(n);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,269 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
|
||||
|
||||
/** This class implements a powerful pseudo-random number generator
|
||||
* developed by Makoto Matsumoto and Takuji Nishimura during
|
||||
* 1996-1997.
|
||||
*
|
||||
* <b>Caveat:</b> It is recommended to use one of WELL generators rather
|
||||
* than the MersenneTwister generator (see
|
||||
* <a href="http://www.iro.umontreal.ca/~panneton/WELLRNG.html">
|
||||
* this paper</a> for more information).
|
||||
*
|
||||
* <p>This generator features an extremely long period
|
||||
* (2<sup>19937</sup>-1) and 623-dimensional equidistribution up to 32
|
||||
* bits accuracy. The home page for this generator is located at <a
|
||||
* href="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html">
|
||||
* http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html</a>.</p>
|
||||
|
||||
* <p>This generator is described in a paper by Makoto Matsumoto and
|
||||
* Takuji Nishimura in 1998: <a
|
||||
* href="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/ARTICLES/mt.pdf">Mersenne
|
||||
* Twister: A 623-Dimensionally Equidistributed Uniform Pseudo-Random
|
||||
* Number Generator</a>, ACM Transactions on Modeling and Computer
|
||||
* Simulation, Vol. 8, No. 1, January 1998, pp 3--30</p>
|
||||
|
||||
* <p>This class is mainly a Java port of the 2002-01-26 version of
|
||||
* the generator written in C by Makoto Matsumoto and Takuji
|
||||
* Nishimura. Here is their original copyright:</p>
|
||||
|
||||
* <table border="0" width="80%" cellpadding="10" align="center" bgcolor="#E0E0E0">
|
||||
* <tr><td>Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
|
||||
* All rights reserved.</td></tr>
|
||||
|
||||
* <tr><td>Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* <ol>
|
||||
* <li>Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.</li>
|
||||
* <li>Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.</li>
|
||||
* <li>The names of its contributors may not be used to endorse or promote
|
||||
* products derived from this software without specific prior written
|
||||
* permission.</li>
|
||||
* </ol></td></tr>
|
||||
|
||||
* <tr><td><strong>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||
* DAMAGE.</strong></td></tr>
|
||||
* </table>
|
||||
|
||||
* @since 2.0
|
||||
|
||||
*/
|
||||
public class MersenneTwister extends BitsStreamGenerator implements Serializable {
|
||||
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 8661194735290153518L;
|
||||
|
||||
/** Size of the bytes pool. */
|
||||
private static final int N = 624;
|
||||
|
||||
/** Period second parameter. */
|
||||
private static final int M = 397;
|
||||
|
||||
/** X * MATRIX_A for X = {0, 1}. */
|
||||
private static final int[] MAG01 = { 0x0, 0x9908b0df };
|
||||
|
||||
/** Bytes pool. */
|
||||
private int[] mt;
|
||||
|
||||
/** Current index in the bytes pool. */
|
||||
private int mti;
|
||||
|
||||
/** Creates a new random number generator.
|
||||
* <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() + System.identityHashCode(this));
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using a single int seed.
|
||||
* @param seed the initial seed (32 bits integer)
|
||||
*/
|
||||
public MersenneTwister(int seed) {
|
||||
mt = new int[N];
|
||||
setSeed(seed);
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using an int array seed.
|
||||
* @param seed the initial seed (32 bits integers array), if null
|
||||
* the seed of the generator will be related to the current time
|
||||
*/
|
||||
public MersenneTwister(int[] seed) {
|
||||
mt = new int[N];
|
||||
setSeed(seed);
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using a single long seed.
|
||||
* @param seed the initial seed (64 bits integer)
|
||||
*/
|
||||
public MersenneTwister(long seed) {
|
||||
mt = new int[N];
|
||||
setSeed(seed);
|
||||
}
|
||||
|
||||
/** Reinitialize the generator as if just built with the given int 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 integer)
|
||||
*/
|
||||
@Override
|
||||
public void setSeed(int seed) {
|
||||
// we use a long masked by 0xffffffffL as a poor man unsigned int
|
||||
long longMT = seed;
|
||||
// NB: unlike original C code, we are working with java longs, the cast below makes masking unnecessary
|
||||
mt[0]= (int) longMT;
|
||||
for (mti = 1; mti < N; ++mti) {
|
||||
// See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier.
|
||||
// initializer from the 2002-01-09 C version by Makoto Matsumoto
|
||||
longMT = (1812433253l * (longMT ^ (longMT >> 30)) + mti) & 0xffffffffL;
|
||||
mt[mti]= (int) longMT;
|
||||
}
|
||||
|
||||
clear(); // Clear normal deviate cache
|
||||
}
|
||||
|
||||
/** 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 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() + System.identityHashCode(this));
|
||||
return;
|
||||
}
|
||||
|
||||
setSeed(19650218);
|
||||
int i = 1;
|
||||
int j = 0;
|
||||
|
||||
for (int k = FastMath.max(N, seed.length); k != 0; k--) {
|
||||
long l0 = (mt[i] & 0x7fffffffl) | ((mt[i] < 0) ? 0x80000000l : 0x0l);
|
||||
long l1 = (mt[i-1] & 0x7fffffffl) | ((mt[i-1] < 0) ? 0x80000000l : 0x0l);
|
||||
long l = (l0 ^ ((l1 ^ (l1 >> 30)) * 1664525l)) + seed[j] + j; // non linear
|
||||
mt[i] = (int) (l & 0xffffffffl);
|
||||
i++; j++;
|
||||
if (i >= N) {
|
||||
mt[0] = mt[N - 1];
|
||||
i = 1;
|
||||
}
|
||||
if (j >= seed.length) {
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (int k = N - 1; k != 0; k--) {
|
||||
long l0 = (mt[i] & 0x7fffffffl) | ((mt[i] < 0) ? 0x80000000l : 0x0l);
|
||||
long l1 = (mt[i-1] & 0x7fffffffl) | ((mt[i-1] < 0) ? 0x80000000l : 0x0l);
|
||||
long l = (l0 ^ ((l1 ^ (l1 >> 30)) * 1566083941l)) - i; // non linear
|
||||
mt[i] = (int) (l & 0xffffffffL);
|
||||
i++;
|
||||
if (i >= N) {
|
||||
mt[0] = mt[N - 1];
|
||||
i = 1;
|
||||
}
|
||||
}
|
||||
|
||||
mt[0] = 0x80000000; // MSB is 1; assuring non-zero initial array
|
||||
|
||||
clear(); // Clear normal deviate cache
|
||||
|
||||
}
|
||||
|
||||
/** Reinitialize the generator as if just built with the given long 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 (64 bits integer)
|
||||
*/
|
||||
@Override
|
||||
public void setSeed(long seed) {
|
||||
setSeed(new int[] { (int) (seed >>> 32), (int) (seed & 0xffffffffl) });
|
||||
}
|
||||
|
||||
/** Generate next pseudorandom number.
|
||||
* <p>This method is the core generation algorithm. It is used by all the
|
||||
* public generation methods for the various primitive types {@link
|
||||
* #nextBoolean()}, {@link #nextBytes(byte[])}, {@link #nextDouble()},
|
||||
* {@link #nextFloat()}, {@link #nextGaussian()}, {@link #nextInt()},
|
||||
* {@link #next(int)} and {@link #nextLong()}.</p>
|
||||
* @param bits number of random bits to produce
|
||||
* @return random bits generated
|
||||
*/
|
||||
@Override
|
||||
protected int next(int bits) {
|
||||
|
||||
int y;
|
||||
|
||||
if (mti >= N) { // generate N words at one time
|
||||
int mtNext = mt[0];
|
||||
for (int k = 0; k < N - M; ++k) {
|
||||
int mtCurr = mtNext;
|
||||
mtNext = mt[k + 1];
|
||||
y = (mtCurr & 0x80000000) | (mtNext & 0x7fffffff);
|
||||
mt[k] = mt[k + M] ^ (y >>> 1) ^ MAG01[y & 0x1];
|
||||
}
|
||||
for (int k = N - M; k < N - 1; ++k) {
|
||||
int mtCurr = mtNext;
|
||||
mtNext = mt[k + 1];
|
||||
y = (mtCurr & 0x80000000) | (mtNext & 0x7fffffff);
|
||||
mt[k] = mt[k + (M - N)] ^ (y >>> 1) ^ MAG01[y & 0x1];
|
||||
}
|
||||
y = (mtNext & 0x80000000) | (mt[0] & 0x7fffffff);
|
||||
mt[N - 1] = mt[M - 1] ^ (y >>> 1) ^ MAG01[y & 0x1];
|
||||
|
||||
mti = 0;
|
||||
}
|
||||
|
||||
y = mt[mti++];
|
||||
|
||||
// tempering
|
||||
y ^= y >>> 11;
|
||||
y ^= (y << 7) & 0x9d2c5680;
|
||||
y ^= (y << 15) & 0xefc60000;
|
||||
y ^= y >>> 18;
|
||||
|
||||
return y >>> (32 - bits);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,199 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Extension of <code>java.util.Random</code> wrapping a
|
||||
* {@link RandomGenerator}.
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
public class RandomAdaptor extends Random implements RandomGenerator {
|
||||
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 2306581345647615033L;
|
||||
|
||||
/** Wrapped randomGenerator instance */
|
||||
private final RandomGenerator randomGenerator;
|
||||
|
||||
/**
|
||||
* Prevent instantiation without a generator argument
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private RandomAdaptor() { randomGenerator = null; }
|
||||
|
||||
/**
|
||||
* Construct a RandomAdaptor wrapping the supplied RandomGenerator.
|
||||
*
|
||||
* @param randomGenerator the wrapped generator
|
||||
*/
|
||||
public RandomAdaptor(RandomGenerator randomGenerator) {
|
||||
this.randomGenerator = randomGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method to create a <code>Random</code> using the supplied
|
||||
* <code>RandomGenerator</code>.
|
||||
*
|
||||
* @param randomGenerator wrapped RandomGenerator instance
|
||||
* @return a Random instance wrapping the RandomGenerator
|
||||
*/
|
||||
public static Random createAdaptor(RandomGenerator randomGenerator) {
|
||||
return new RandomAdaptor(randomGenerator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next pseudorandom, uniformly distributed
|
||||
* <code>boolean</code> value from this random number generator's
|
||||
* sequence.
|
||||
*
|
||||
* @return the next pseudorandom, uniformly distributed
|
||||
* <code>boolean</code> value from this random number generator's
|
||||
* sequence
|
||||
*/
|
||||
@Override
|
||||
public boolean nextBoolean() {
|
||||
return randomGenerator.nextBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates random bytes and places them into a user-supplied
|
||||
* byte array. The number of random bytes produced is equal to
|
||||
* the length of the byte array.
|
||||
*
|
||||
* @param bytes the non-null byte array in which to put the
|
||||
* random bytes
|
||||
*/
|
||||
@Override
|
||||
public void nextBytes(byte[] bytes) {
|
||||
randomGenerator.nextBytes(bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next pseudorandom, uniformly distributed
|
||||
* <code>double</code> value between <code>0.0</code> and
|
||||
* <code>1.0</code> from this random number generator's sequence.
|
||||
*
|
||||
* @return the next pseudorandom, uniformly distributed
|
||||
* <code>double</code> value between <code>0.0</code> and
|
||||
* <code>1.0</code> from this random number generator's sequence
|
||||
*/
|
||||
@Override
|
||||
public double nextDouble() {
|
||||
return randomGenerator.nextDouble();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next pseudorandom, uniformly distributed <code>float</code>
|
||||
* value between <code>0.0</code> and <code>1.0</code> from this random
|
||||
* number generator's sequence.
|
||||
*
|
||||
* @return the next pseudorandom, uniformly distributed <code>float</code>
|
||||
* value between <code>0.0</code> and <code>1.0</code> from this
|
||||
* random number generator's sequence
|
||||
*/
|
||||
@Override
|
||||
public float nextFloat() {
|
||||
return randomGenerator.nextFloat();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next pseudorandom, Gaussian ("normally") distributed
|
||||
* <code>double</code> value with mean <code>0.0</code> and standard
|
||||
* deviation <code>1.0</code> from this random number generator's sequence.
|
||||
*
|
||||
* @return the next pseudorandom, Gaussian ("normally") distributed
|
||||
* <code>double</code> value with mean <code>0.0</code> and
|
||||
* standard deviation <code>1.0</code> from this random number
|
||||
* generator's sequence
|
||||
*/
|
||||
@Override
|
||||
public double nextGaussian() {
|
||||
return randomGenerator.nextGaussian();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next pseudorandom, uniformly distributed <code>int</code>
|
||||
* value from this random number generator's sequence.
|
||||
* All 2<font size="-1"><sup>32</sup></font> possible {@code int} values
|
||||
* should be produced with (approximately) equal probability.
|
||||
*
|
||||
* @return the next pseudorandom, uniformly distributed <code>int</code>
|
||||
* value from this random number generator's sequence
|
||||
*/
|
||||
@Override
|
||||
public int nextInt() {
|
||||
return randomGenerator.nextInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pseudorandom, uniformly distributed {@code int} value
|
||||
* between 0 (inclusive) and the specified value (exclusive), drawn from
|
||||
* this random number generator's sequence.
|
||||
*
|
||||
* @param n the bound on the random number to be returned. Must be
|
||||
* positive.
|
||||
* @return a pseudorandom, uniformly distributed {@code int}
|
||||
* value between 0 (inclusive) and n (exclusive).
|
||||
* @throws IllegalArgumentException if n is not positive.
|
||||
*/
|
||||
@Override
|
||||
public int nextInt(int n) {
|
||||
return randomGenerator.nextInt(n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next pseudorandom, uniformly distributed <code>long</code>
|
||||
* value from this random number generator's sequence. All
|
||||
* 2<font size="-1"><sup>64</sup></font> possible {@code long} values
|
||||
* should be produced with (approximately) equal probability.
|
||||
*
|
||||
* @return the next pseudorandom, uniformly distributed <code>long</code>
|
||||
*value from this random number generator's sequence
|
||||
*/
|
||||
@Override
|
||||
public long nextLong() {
|
||||
return randomGenerator.nextLong();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void setSeed(int seed) {
|
||||
if (randomGenerator != null) { // required to avoid NPE in constructor
|
||||
randomGenerator.setSeed(seed);
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void setSeed(int[] seed) {
|
||||
if (randomGenerator != null) { // required to avoid NPE in constructor
|
||||
randomGenerator.setSeed(seed);
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void setSeed(long seed) {
|
||||
if (randomGenerator != null) { // required to avoid NPE in constructor
|
||||
randomGenerator.setSeed(seed);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -18,11 +18,12 @@ package org.apache.commons.math4.random;
|
|||
|
||||
|
||||
/**
|
||||
* Interface extracted from <code>java.util.Random</code>. This interface is
|
||||
* implemented by {@link AbstractRandomGenerator}.
|
||||
* Interface extracted from <code>java.util.Random</code>.
|
||||
*
|
||||
* @since 1.1
|
||||
* @deprecated As of 4.0. Please use {@link org.apache.commons.math4.rng.UniformRandomProvider} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface RandomGenerator {
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,133 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
||||
|
||||
/**
|
||||
* Utilities for creating {@link RandomGenerator} instances.
|
||||
*
|
||||
* @since 3.3
|
||||
*/
|
||||
public class RandomGeneratorFactory {
|
||||
/**
|
||||
* Class contains only static methods.
|
||||
*/
|
||||
private RandomGeneratorFactory() {}
|
||||
|
||||
/**
|
||||
* Creates a {@link RandomDataGenerator} instance that wraps a
|
||||
* {@link Random} instance.
|
||||
*
|
||||
* @param rng JDK {@link Random} instance that will generate the
|
||||
* the random data.
|
||||
* @return the given RNG, wrapped in a {@link RandomGenerator}.
|
||||
*/
|
||||
public static RandomGenerator createRandomGenerator(final Random rng) {
|
||||
return new RandomGenerator() {
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void setSeed(int seed) {
|
||||
rng.setSeed((long) seed);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void setSeed(int[] seed) {
|
||||
rng.setSeed(convertToLong(seed));
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void setSeed(long seed) {
|
||||
rng.setSeed(seed);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void nextBytes(byte[] bytes) {
|
||||
rng.nextBytes(bytes);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public int nextInt() {
|
||||
return rng.nextInt();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public int nextInt(int n) {
|
||||
if (n <= 0) {
|
||||
throw new NotStrictlyPositiveException(n);
|
||||
}
|
||||
return rng.nextInt(n);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public long nextLong() {
|
||||
return rng.nextLong();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public boolean nextBoolean() {
|
||||
return rng.nextBoolean();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public float nextFloat() {
|
||||
return rng.nextFloat();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public double nextDouble() {
|
||||
return rng.nextDouble();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public double nextGaussian() {
|
||||
return rng.nextGaussian();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts seed from one representation to another.
|
||||
*
|
||||
* @param seed Original seed.
|
||||
* @return the converted seed.
|
||||
*/
|
||||
public static long convertToLong(int[] seed) {
|
||||
// The following number is the largest prime that fits
|
||||
// in 32 bits (i.e. 2^32 - 5).
|
||||
final long prime = 4294967291l;
|
||||
|
||||
long combined = 0l;
|
||||
for (int s : seed) {
|
||||
combined = combined * prime + s;
|
||||
}
|
||||
|
||||
return combined;
|
||||
}
|
||||
}
|
|
@ -50,7 +50,7 @@ public class UnitSphereRandomVectorGenerator
|
|||
this.rand = new NormalDistribution().createSampler(rng);
|
||||
}
|
||||
/**
|
||||
* Create an object that will use a default RNG ({@link MersenneTwister}),
|
||||
* Create an object that will use a {@link RandomSource#MT_64 default RNG},
|
||||
* in order to generate the individual components.
|
||||
*
|
||||
* @param dimension Space dimension.
|
||||
|
|
|
@ -1,445 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.commons.math4.random;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.commons.math4.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math4.exception.MathIllegalStateException;
|
||||
import org.apache.commons.math4.exception.NullArgumentException;
|
||||
import org.apache.commons.math4.exception.ZeroException;
|
||||
import org.apache.commons.math4.exception.util.LocalizedFormats;
|
||||
|
||||
/**
|
||||
* Generates values for use in simulation applications.
|
||||
* <p>
|
||||
* How values are generated is determined by the <code>mode</code>
|
||||
* property.</p>
|
||||
* <p>
|
||||
* Supported <code>mode</code> values are: <ul>
|
||||
* <li> DIGEST_MODE -- uses an empirical distribution </li>
|
||||
* <li> REPLAY_MODE -- replays data from <code>valuesFileURL</code></li>
|
||||
* <li> UNIFORM_MODE -- generates uniformly distributed random values with
|
||||
* mean = <code>mu</code> </li>
|
||||
* <li> EXPONENTIAL_MODE -- generates exponentially distributed random values
|
||||
* with mean = <code>mu</code></li>
|
||||
* <li> GAUSSIAN_MODE -- generates Gaussian distributed random values with
|
||||
* mean = <code>mu</code> and
|
||||
* standard deviation = <code>sigma</code></li>
|
||||
* <li> CONSTANT_MODE -- returns <code>mu</code> every time.</li></ul></p>
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ValueServer {
|
||||
|
||||
/** Use empirical distribution. */
|
||||
public static final int DIGEST_MODE = 0;
|
||||
|
||||
/** Replay data from valuesFilePath. */
|
||||
public static final int REPLAY_MODE = 1;
|
||||
|
||||
/** Uniform random deviates with mean = μ. */
|
||||
public static final int UNIFORM_MODE = 2;
|
||||
|
||||
/** Exponential random deviates with mean = μ. */
|
||||
public static final int EXPONENTIAL_MODE = 3;
|
||||
|
||||
/** Gaussian random deviates with mean = μ, std dev = σ. */
|
||||
public static final int GAUSSIAN_MODE = 4;
|
||||
|
||||
/** Always return mu */
|
||||
public static final int CONSTANT_MODE = 5;
|
||||
|
||||
/** mode determines how values are generated. */
|
||||
private int mode = 5;
|
||||
|
||||
/** URI to raw data values. */
|
||||
private URL valuesFileURL = null;
|
||||
|
||||
/** Mean for use with non-data-driven modes. */
|
||||
private double mu = 0.0;
|
||||
|
||||
/** Standard deviation for use with GAUSSIAN_MODE. */
|
||||
private double sigma = 0.0;
|
||||
|
||||
/** Empirical probability distribution for use with DIGEST_MODE. */
|
||||
private EmpiricalDistribution empiricalDistribution = null;
|
||||
|
||||
/** File pointer for REPLAY_MODE. */
|
||||
private BufferedReader filePointer = null;
|
||||
|
||||
/** RandomDataImpl to use for random data generation. */
|
||||
private final RandomDataGenerator randomData;
|
||||
|
||||
// Data generation modes ======================================
|
||||
|
||||
/** Creates new ValueServer */
|
||||
public ValueServer() {
|
||||
randomData = new RandomDataGenerator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a ValueServer instance using a RandomGenerator as its source
|
||||
* of random data.
|
||||
*
|
||||
* @since 3.1
|
||||
* @param generator source of random data
|
||||
*/
|
||||
public ValueServer(RandomGenerator generator) {
|
||||
this.randomData = new RandomDataGenerator(generator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next generated value, generated according
|
||||
* to the mode value (see MODE constants).
|
||||
*
|
||||
* @return generated value
|
||||
* @throws IOException in REPLAY_MODE if a file I/O error occurs
|
||||
* @throws MathIllegalStateException if mode is not recognized
|
||||
* @throws MathIllegalArgumentException if the underlying random generator thwrows one
|
||||
*/
|
||||
public double getNext() throws IOException, MathIllegalStateException, MathIllegalArgumentException {
|
||||
switch (mode) {
|
||||
case DIGEST_MODE: return getNextDigest();
|
||||
case REPLAY_MODE: return getNextReplay();
|
||||
case UNIFORM_MODE: return getNextUniform();
|
||||
case EXPONENTIAL_MODE: return getNextExponential();
|
||||
case GAUSSIAN_MODE: return getNextGaussian();
|
||||
case CONSTANT_MODE: return mu;
|
||||
default: throw new MathIllegalStateException(
|
||||
LocalizedFormats.UNKNOWN_MODE,
|
||||
mode,
|
||||
"DIGEST_MODE", DIGEST_MODE, "REPLAY_MODE", REPLAY_MODE,
|
||||
"UNIFORM_MODE", UNIFORM_MODE, "EXPONENTIAL_MODE", EXPONENTIAL_MODE,
|
||||
"GAUSSIAN_MODE", GAUSSIAN_MODE, "CONSTANT_MODE", CONSTANT_MODE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills the input array with values generated using getNext() repeatedly.
|
||||
*
|
||||
* @param values array to be filled
|
||||
* @throws IOException in REPLAY_MODE if a file I/O error occurs
|
||||
* @throws MathIllegalStateException if mode is not recognized
|
||||
* @throws MathIllegalArgumentException if the underlying random generator thwrows one
|
||||
*/
|
||||
public void fill(double[] values)
|
||||
throws IOException, MathIllegalStateException, MathIllegalArgumentException {
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
values[i] = getNext();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of length <code>length</code> with values generated
|
||||
* using getNext() repeatedly.
|
||||
*
|
||||
* @param length length of output array
|
||||
* @return array of generated values
|
||||
* @throws IOException in REPLAY_MODE if a file I/O error occurs
|
||||
* @throws MathIllegalStateException if mode is not recognized
|
||||
* @throws MathIllegalArgumentException if the underlying random generator thwrows one
|
||||
*/
|
||||
public double[] fill(int length)
|
||||
throws IOException, MathIllegalStateException, MathIllegalArgumentException {
|
||||
double[] out = new double[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
out[i] = getNext();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the empirical distribution using values from the file
|
||||
* in <code>valuesFileURL</code>, using the default number of bins.
|
||||
* <p>
|
||||
* <code>valuesFileURL</code> must exist and be
|
||||
* readable by *this at runtime.</p>
|
||||
* <p>
|
||||
* This method must be called before using <code>getNext()</code>
|
||||
* with <code>mode = DIGEST_MODE</code></p>
|
||||
*
|
||||
* @throws IOException if an I/O error occurs reading the input file
|
||||
* @throws NullArgumentException if the {@code valuesFileURL} has not been set
|
||||
* @throws ZeroException if URL contains no data
|
||||
*/
|
||||
public void computeDistribution() throws IOException, ZeroException, NullArgumentException {
|
||||
computeDistribution(EmpiricalDistribution.DEFAULT_BIN_COUNT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the empirical distribution using values from the file
|
||||
* in <code>valuesFileURL</code> and <code>binCount</code> bins.
|
||||
* <p>
|
||||
* <code>valuesFileURL</code> must exist and be readable by this process
|
||||
* at runtime.</p>
|
||||
* <p>
|
||||
* This method must be called before using <code>getNext()</code>
|
||||
* with <code>mode = DIGEST_MODE</code></p>
|
||||
*
|
||||
* @param binCount the number of bins used in computing the empirical
|
||||
* distribution
|
||||
* @throws NullArgumentException if the {@code valuesFileURL} has not been set
|
||||
* @throws IOException if an error occurs reading the input file
|
||||
* @throws ZeroException if URL contains no data
|
||||
*/
|
||||
public void computeDistribution(int binCount) throws NullArgumentException, IOException, ZeroException {
|
||||
empiricalDistribution = new EmpiricalDistribution(binCount);
|
||||
empiricalDistribution.load(valuesFileURL);
|
||||
mu = empiricalDistribution.getSampleStats().getMean();
|
||||
sigma = empiricalDistribution.getSampleStats().getStandardDeviation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data generation mode. See {@link ValueServer the class javadoc}
|
||||
* for description of the valid values of this property.
|
||||
*
|
||||
* @return Value of property mode.
|
||||
*/
|
||||
public int getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the data generation mode.
|
||||
*
|
||||
* @param mode New value of the data generation mode.
|
||||
*/
|
||||
public void setMode(int mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL for the file used to build the empirical distribution
|
||||
* when using {@link #DIGEST_MODE}.
|
||||
*
|
||||
* @return Values file URL.
|
||||
*/
|
||||
public URL getValuesFileURL() {
|
||||
return valuesFileURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link #getValuesFileURL() values file URL} using a string
|
||||
* URL representation.
|
||||
*
|
||||
* @param url String representation for new valuesFileURL.
|
||||
* @throws MalformedURLException if url is not well formed
|
||||
*/
|
||||
public void setValuesFileURL(String url) throws MalformedURLException {
|
||||
this.valuesFileURL = new URL(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the the {@link #getValuesFileURL() values file URL}.
|
||||
*
|
||||
* <p>The values file <i>must</i> be an ASCII text file containing one
|
||||
* valid numeric entry per line.</p>
|
||||
*
|
||||
* @param url URL of the values file.
|
||||
*/
|
||||
public void setValuesFileURL(URL url) {
|
||||
this.valuesFileURL = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link EmpiricalDistribution} used when operating in {@value #DIGEST_MODE}.
|
||||
*
|
||||
* @return EmpircalDistribution built by {@link #computeDistribution()}
|
||||
*/
|
||||
public EmpiricalDistribution getEmpiricalDistribution() {
|
||||
return empiricalDistribution;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets REPLAY_MODE file pointer to the beginning of the <code>valuesFileURL</code>.
|
||||
*
|
||||
* @throws IOException if an error occurs opening the file
|
||||
* @throws NullPointerException if the {@code valuesFileURL} has not been set.
|
||||
*/
|
||||
public void resetReplayFile() throws IOException {
|
||||
if (filePointer != null) {
|
||||
try {
|
||||
filePointer.close();
|
||||
filePointer = null;
|
||||
} catch (IOException ex) { //NOPMD
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
filePointer = new BufferedReader(new InputStreamReader(valuesFileURL.openStream(), "UTF-8"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes {@code valuesFileURL} after use in REPLAY_MODE.
|
||||
*
|
||||
* @throws IOException if an error occurs closing the file
|
||||
*/
|
||||
public void closeReplayFile() throws IOException {
|
||||
if (filePointer != null) {
|
||||
filePointer.close();
|
||||
filePointer = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mean used when operating in {@link #GAUSSIAN_MODE}, {@link #EXPONENTIAL_MODE}
|
||||
* or {@link #UNIFORM_MODE}. When operating in {@link #CONSTANT_MODE}, this is the constant
|
||||
* value always returned. Calling {@link #computeDistribution()} sets this value to the
|
||||
* overall mean of the values in the {@link #getValuesFileURL() values file}.
|
||||
*
|
||||
* @return Mean used in data generation.
|
||||
*/
|
||||
public double getMu() {
|
||||
return mu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link #getMu() mean} used in data generation. Note that calling this method
|
||||
* after {@link #computeDistribution()} has been called will have no effect on data
|
||||
* generated in {@link #DIGEST_MODE}.
|
||||
*
|
||||
* @param mu new Mean value.
|
||||
*/
|
||||
public void setMu(double mu) {
|
||||
this.mu = mu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the standard deviation used when operating in {@link #GAUSSIAN_MODE}.
|
||||
* Calling {@link #computeDistribution()} sets this value to the overall standard
|
||||
* deviation of the values in the {@link #getValuesFileURL() values file}. This
|
||||
* property has no effect when the data generation mode is not
|
||||
* {@link #GAUSSIAN_MODE}.
|
||||
*
|
||||
* @return Standard deviation used when operating in {@link #GAUSSIAN_MODE}.
|
||||
*/
|
||||
public double getSigma() {
|
||||
return sigma;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link #getSigma() standard deviation} used in {@link #GAUSSIAN_MODE}.
|
||||
*
|
||||
* @param sigma New standard deviation.
|
||||
*/
|
||||
public void setSigma(double sigma) {
|
||||
this.sigma = sigma;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reseeds the random data generator.
|
||||
*
|
||||
* @param seed Value with which to reseed the {@link RandomDataGenerator}
|
||||
* used to generate random data.
|
||||
*/
|
||||
public void reSeed(long seed) {
|
||||
randomData.reSeed(seed);
|
||||
}
|
||||
|
||||
//------------- private methods ---------------------------------
|
||||
|
||||
/**
|
||||
* Gets a random value in DIGEST_MODE.
|
||||
* <p>
|
||||
* <strong>Preconditions</strong>: <ul>
|
||||
* <li>Before this method is called, <code>computeDistribution()</code>
|
||||
* must have completed successfully; otherwise an
|
||||
* <code>IllegalStateException</code> will be thrown</li></ul></p>
|
||||
*
|
||||
* @return next random value from the empirical distribution digest
|
||||
* @throws MathIllegalStateException if digest has not been initialized
|
||||
*/
|
||||
private double getNextDigest() throws MathIllegalStateException {
|
||||
if ((empiricalDistribution == null) ||
|
||||
(empiricalDistribution.getBinStats().size() == 0)) {
|
||||
throw new MathIllegalStateException(LocalizedFormats.DIGEST_NOT_INITIALIZED);
|
||||
}
|
||||
return empiricalDistribution.createSampler(randomData.getRandomProvider()).sample();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets next sequential value from the <code>valuesFileURL</code>.
|
||||
* <p>
|
||||
* Throws an IOException if the read fails.</p>
|
||||
* <p>
|
||||
* This method will open the <code>valuesFileURL</code> if there is no
|
||||
* replay file open.</p>
|
||||
* <p>
|
||||
* The <code>valuesFileURL</code> will be closed and reopened to wrap around
|
||||
* from EOF to BOF if EOF is encountered. EOFException (which is a kind of
|
||||
* IOException) may still be thrown if the <code>valuesFileURL</code> is
|
||||
* empty.</p>
|
||||
*
|
||||
* @return next value from the replay file
|
||||
* @throws IOException if there is a problem reading from the file
|
||||
* @throws MathIllegalStateException if URL contains no data
|
||||
* @throws NumberFormatException if an invalid numeric string is
|
||||
* encountered in the file
|
||||
*/
|
||||
private double getNextReplay() throws IOException, MathIllegalStateException {
|
||||
String str = null;
|
||||
if (filePointer == null) {
|
||||
resetReplayFile();
|
||||
}
|
||||
if ((str = filePointer.readLine()) == null) {
|
||||
// we have probably reached end of file, wrap around from EOF to BOF
|
||||
closeReplayFile();
|
||||
resetReplayFile();
|
||||
if ((str = filePointer.readLine()) == null) {
|
||||
throw new MathIllegalStateException(LocalizedFormats.URL_CONTAINS_NO_DATA,
|
||||
valuesFileURL);
|
||||
}
|
||||
}
|
||||
return Double.parseDouble(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a uniformly distributed random value with mean = mu.
|
||||
*
|
||||
* @return random uniform value
|
||||
* @throws MathIllegalArgumentException if the underlying random generator thwrows one
|
||||
*/
|
||||
private double getNextUniform() throws MathIllegalArgumentException {
|
||||
return randomData.nextUniform(0, 2 * mu);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an exponentially distributed random value with mean = mu.
|
||||
*
|
||||
* @return random exponential value
|
||||
* @throws MathIllegalArgumentException if the underlying random generator thwrows one
|
||||
*/
|
||||
private double getNextExponential() throws MathIllegalArgumentException {
|
||||
return randomData.nextExponential(mu);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Gaussian distributed random value with mean = mu
|
||||
* and standard deviation = sigma.
|
||||
*
|
||||
* @return random Gaussian value
|
||||
* @throws MathIllegalArgumentException if the underlying random generator thwrows one
|
||||
*/
|
||||
private double getNextGaussian() throws MathIllegalArgumentException {
|
||||
return randomData.nextGaussian(mu, sigma);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
/** This class implements the WELL1024a pseudo-random number generator
|
||||
* from François Panneton, Pierre L'Ecuyer and Makoto Matsumoto.
|
||||
* <p>
|
||||
* This generator is described in a paper by François Panneton,
|
||||
* Pierre L'Ecuyer and Makoto Matsumoto <a
|
||||
* href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng.pdf">Improved
|
||||
* Long-Period Generators Based on Linear Recurrences Modulo 2</a> ACM
|
||||
* Transactions on Mathematical Software, 32, 1 (2006). The errata for the paper
|
||||
* are in <a href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng-errata.txt">wellrng-errata.txt</a>.</p>
|
||||
*
|
||||
* @see <a href="http://www.iro.umontreal.ca/~panneton/WELLRNG.html">WELL Random number generator</a>
|
||||
* @since 2.2
|
||||
*/
|
||||
public class Well1024a extends AbstractWell {
|
||||
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 20150223L;
|
||||
|
||||
/** Number of bits in the pool. */
|
||||
private static final int K = 1024;
|
||||
|
||||
/** First parameter of the algorithm. */
|
||||
private static final int M1 = 3;
|
||||
|
||||
/** Second parameter of the algorithm. */
|
||||
private static final int M2 = 24;
|
||||
|
||||
/** Third parameter of the algorithm. */
|
||||
private static final int M3 = 10;
|
||||
|
||||
/** The indirection index table. */
|
||||
private static final IndexTable TABLE = new IndexTable(K, M1, M2, M3);
|
||||
|
||||
/** Creates a new random number generator.
|
||||
* <p>The instance is initialized using the current time as the
|
||||
* seed.</p>
|
||||
*/
|
||||
public Well1024a() {
|
||||
super(K);
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using a single int seed.
|
||||
* @param seed the initial seed (32 bits integer)
|
||||
*/
|
||||
public Well1024a(int seed) {
|
||||
super(K, seed);
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using an int array seed.
|
||||
* @param seed the initial seed (32 bits integers array), if null
|
||||
* the seed of the generator will be related to the current time
|
||||
*/
|
||||
public Well1024a(int[] seed) {
|
||||
super(K, seed);
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using a single long seed.
|
||||
* @param seed the initial seed (64 bits integer)
|
||||
*/
|
||||
public Well1024a(long seed) {
|
||||
super(K, seed);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected int next(final int bits) {
|
||||
|
||||
final int indexRm1 = TABLE.getIndexPred(index);
|
||||
|
||||
final int v0 = v[index];
|
||||
final int vM1 = v[TABLE.getIndexM1(index)];
|
||||
final int vM2 = v[TABLE.getIndexM2(index)];
|
||||
final int vM3 = v[TABLE.getIndexM3(index)];
|
||||
|
||||
final int z0 = v[indexRm1];
|
||||
final int z1 = v0 ^ (vM1 ^ (vM1 >>> 8));
|
||||
final int z2 = (vM2 ^ (vM2 << 19)) ^ (vM3 ^ (vM3 << 14));
|
||||
final int z3 = z1 ^ z2;
|
||||
final int z4 = (z0 ^ (z0 << 11)) ^ (z1 ^ (z1 << 7)) ^ (z2 ^ (z2 << 13));
|
||||
|
||||
v[index] = z3;
|
||||
v[indexRm1] = z4;
|
||||
index = indexRm1;
|
||||
|
||||
return z4 >>> (32 - bits);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,110 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
|
||||
/** This class implements the WELL19937a pseudo-random number generator
|
||||
* from François Panneton, Pierre L'Ecuyer and Makoto Matsumoto.
|
||||
* <p>
|
||||
* This generator is described in a paper by François Panneton,
|
||||
* Pierre L'Ecuyer and Makoto Matsumoto <a
|
||||
* href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng.pdf">Improved
|
||||
* Long-Period Generators Based on Linear Recurrences Modulo 2</a> ACM
|
||||
* Transactions on Mathematical Software, 32, 1 (2006). The errata for the paper
|
||||
* are in <a href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng-errata.txt">wellrng-errata.txt</a>.</p>
|
||||
*
|
||||
* @see <a href="http://www.iro.umontreal.ca/~panneton/WELLRNG.html">WELL Random number generator</a>
|
||||
* @since 2.2
|
||||
*/
|
||||
public class Well19937a extends AbstractWell {
|
||||
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 20150223L;
|
||||
|
||||
/** Number of bits in the pool. */
|
||||
private static final int K = 19937;
|
||||
|
||||
/** First parameter of the algorithm. */
|
||||
private static final int M1 = 70;
|
||||
|
||||
/** Second parameter of the algorithm. */
|
||||
private static final int M2 = 179;
|
||||
|
||||
/** Third parameter of the algorithm. */
|
||||
private static final int M3 = 449;
|
||||
|
||||
/** The indirection index table. */
|
||||
private static final IndexTable TABLE = new IndexTable(K, M1, M2, M3);
|
||||
|
||||
/** Creates a new random number generator.
|
||||
* <p>The instance is initialized using the current time as the
|
||||
* seed.</p>
|
||||
*/
|
||||
public Well19937a() {
|
||||
super(K);
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using a single int seed.
|
||||
* @param seed the initial seed (32 bits integer)
|
||||
*/
|
||||
public Well19937a(int seed) {
|
||||
super(K, seed);
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using an int array seed.
|
||||
* @param seed the initial seed (32 bits integers array), if null
|
||||
* the seed of the generator will be related to the current time
|
||||
*/
|
||||
public Well19937a(int[] seed) {
|
||||
super(K, seed);
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using a single long seed.
|
||||
* @param seed the initial seed (64 bits integer)
|
||||
*/
|
||||
public Well19937a(long seed) {
|
||||
super(K, seed);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected int next(final int bits) {
|
||||
|
||||
final int indexRm1 = TABLE.getIndexPred(index);
|
||||
final int indexRm2 = TABLE.getIndexPred2(index);
|
||||
|
||||
final int v0 = v[index];
|
||||
final int vM1 = v[TABLE.getIndexM1(index)];
|
||||
final int vM2 = v[TABLE.getIndexM2(index)];
|
||||
final int vM3 = v[TABLE.getIndexM3(index)];
|
||||
|
||||
final int z0 = (0x80000000 & v[indexRm1]) ^ (0x7FFFFFFF & v[indexRm2]);
|
||||
final int z1 = (v0 ^ (v0 << 25)) ^ (vM1 ^ (vM1 >>> 27));
|
||||
final int z2 = (vM2 >>> 9) ^ (vM3 ^ (vM3 >>> 1));
|
||||
final int z3 = z1 ^ z2;
|
||||
final int z4 = z0 ^ (z1 ^ (z1 << 9)) ^ (z2 ^ (z2 << 21)) ^ (z3 ^ (z3 >>> 21));
|
||||
|
||||
v[index] = z3;
|
||||
v[indexRm1] = z4;
|
||||
v[indexRm2] &= 0x80000000;
|
||||
index = indexRm1;
|
||||
|
||||
return z4 >>> (32 - bits);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
|
||||
/** This class implements the WELL19937c pseudo-random number generator
|
||||
* from François Panneton, Pierre L'Ecuyer and Makoto Matsumoto.
|
||||
* <p>
|
||||
* This generator is described in a paper by François Panneton,
|
||||
* Pierre L'Ecuyer and Makoto Matsumoto <a
|
||||
* href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng.pdf">Improved
|
||||
* Long-Period Generators Based on Linear Recurrences Modulo 2</a> ACM
|
||||
* Transactions on Mathematical Software, 32, 1 (2006). The errata for the paper
|
||||
* are in <a href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng-errata.txt">wellrng-errata.txt</a>.</p>
|
||||
*
|
||||
* @see <a href="http://www.iro.umontreal.ca/~panneton/WELLRNG.html">WELL Random number generator</a>
|
||||
* @since 2.2
|
||||
*/
|
||||
public class Well19937c extends AbstractWell {
|
||||
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 20150223L;
|
||||
|
||||
/** Number of bits in the pool. */
|
||||
private static final int K = 19937;
|
||||
|
||||
/** First parameter of the algorithm. */
|
||||
private static final int M1 = 70;
|
||||
|
||||
/** Second parameter of the algorithm. */
|
||||
private static final int M2 = 179;
|
||||
|
||||
/** Third parameter of the algorithm. */
|
||||
private static final int M3 = 449;
|
||||
|
||||
/** The indirection index table. */
|
||||
private static final IndexTable TABLE = new IndexTable(K, M1, M2, M3);
|
||||
|
||||
/** Creates a new random number generator.
|
||||
* <p>The instance is initialized using the current time as the
|
||||
* seed.</p>
|
||||
*/
|
||||
public Well19937c() {
|
||||
super(K);
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using a single int seed.
|
||||
* @param seed the initial seed (32 bits integer)
|
||||
*/
|
||||
public Well19937c(int seed) {
|
||||
super(K, seed);
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using an int array seed.
|
||||
* @param seed the initial seed (32 bits integers array), if null
|
||||
* the seed of the generator will be related to the current time
|
||||
*/
|
||||
public Well19937c(int[] seed) {
|
||||
super(K, seed);
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using a single long seed.
|
||||
* @param seed the initial seed (64 bits integer)
|
||||
*/
|
||||
public Well19937c(long seed) {
|
||||
super(K, seed);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected int next(final int bits) {
|
||||
|
||||
final int indexRm1 = TABLE.getIndexPred(index);
|
||||
final int indexRm2 = TABLE.getIndexPred2(index);
|
||||
|
||||
final int v0 = v[index];
|
||||
final int vM1 = v[TABLE.getIndexM1(index)];
|
||||
final int vM2 = v[TABLE.getIndexM2(index)];
|
||||
final int vM3 = v[TABLE.getIndexM3(index)];
|
||||
|
||||
final int z0 = (0x80000000 & v[indexRm1]) ^ (0x7FFFFFFF & v[indexRm2]);
|
||||
final int z1 = (v0 ^ (v0 << 25)) ^ (vM1 ^ (vM1 >>> 27));
|
||||
final int z2 = (vM2 >>> 9) ^ (vM3 ^ (vM3 >>> 1));
|
||||
final int z3 = z1 ^ z2;
|
||||
int z4 = z0 ^ (z1 ^ (z1 << 9)) ^ (z2 ^ (z2 << 21)) ^ (z3 ^ (z3 >>> 21));
|
||||
|
||||
v[index] = z3;
|
||||
v[indexRm1] = z4;
|
||||
v[indexRm2] &= 0x80000000;
|
||||
index = indexRm1;
|
||||
|
||||
// add Matsumoto-Kurita tempering
|
||||
// to get a maximally-equidistributed generator
|
||||
z4 ^= (z4 << 7) & 0xe46e1700;
|
||||
z4 ^= (z4 << 15) & 0x9b868000;
|
||||
|
||||
return z4 >>> (32 - bits);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
/** This class implements the WELL44497a pseudo-random number generator
|
||||
* from François Panneton, Pierre L'Ecuyer and Makoto Matsumoto.
|
||||
* <p>
|
||||
* This generator is described in a paper by François Panneton,
|
||||
* Pierre L'Ecuyer and Makoto Matsumoto <a
|
||||
* href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng.pdf">Improved
|
||||
* Long-Period Generators Based on Linear Recurrences Modulo 2</a> ACM
|
||||
* Transactions on Mathematical Software, 32, 1 (2006). The errata for the paper
|
||||
* are in <a href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng-errata.txt">wellrng-errata.txt</a>.</p>
|
||||
*
|
||||
* @see <a href="http://www.iro.umontreal.ca/~panneton/WELLRNG.html">WELL Random number generator</a>
|
||||
* @since 2.2
|
||||
*/
|
||||
public class Well44497a extends AbstractWell {
|
||||
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 20150223L;
|
||||
|
||||
/** Number of bits in the pool. */
|
||||
private static final int K = 44497;
|
||||
|
||||
/** First parameter of the algorithm. */
|
||||
private static final int M1 = 23;
|
||||
|
||||
/** Second parameter of the algorithm. */
|
||||
private static final int M2 = 481;
|
||||
|
||||
/** Third parameter of the algorithm. */
|
||||
private static final int M3 = 229;
|
||||
|
||||
/** The indirection index table. */
|
||||
private static final IndexTable TABLE = new IndexTable(K, M1, M2, M3);
|
||||
|
||||
/** Creates a new random number generator.
|
||||
* <p>The instance is initialized using the current time as the
|
||||
* seed.</p>
|
||||
*/
|
||||
public Well44497a() {
|
||||
super(K);
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using a single int seed.
|
||||
* @param seed the initial seed (32 bits integer)
|
||||
*/
|
||||
public Well44497a(int seed) {
|
||||
super(K, seed);
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using an int array seed.
|
||||
* @param seed the initial seed (32 bits integers array), if null
|
||||
* the seed of the generator will be related to the current time
|
||||
*/
|
||||
public Well44497a(int[] seed) {
|
||||
super(K, seed);
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using a single long seed.
|
||||
* @param seed the initial seed (64 bits integer)
|
||||
*/
|
||||
public Well44497a(long seed) {
|
||||
super(K, seed);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected int next(final int bits) {
|
||||
|
||||
final int indexRm1 = TABLE.getIndexPred(index);
|
||||
final int indexRm2 = TABLE.getIndexPred2(index);
|
||||
|
||||
final int v0 = v[index];
|
||||
final int vM1 = v[TABLE.getIndexM1(index)];
|
||||
final int vM2 = v[TABLE.getIndexM2(index)];
|
||||
final int vM3 = v[TABLE.getIndexM3(index)];
|
||||
|
||||
// the values below include the errata of the original article
|
||||
final int z0 = (0xFFFF8000 & v[indexRm1]) ^ (0x00007FFF & v[indexRm2]);
|
||||
final int z1 = (v0 ^ (v0 << 24)) ^ (vM1 ^ (vM1 >>> 30));
|
||||
final int z2 = (vM2 ^ (vM2 << 10)) ^ (vM3 << 26);
|
||||
final int z3 = z1 ^ z2;
|
||||
final int z2Prime = ((z2 << 9) ^ (z2 >>> 23)) & 0xfbffffff;
|
||||
final int z2Second = ((z2 & 0x00020000) != 0) ? (z2Prime ^ 0xb729fcec) : z2Prime;
|
||||
final int z4 = z0 ^ (z1 ^ (z1 >>> 20)) ^ z2Second ^ z3;
|
||||
|
||||
v[index] = z3;
|
||||
v[indexRm1] = z4;
|
||||
v[indexRm2] &= 0xFFFF8000;
|
||||
index = indexRm1;
|
||||
|
||||
return z4 >>> (32 - bits);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
/** This class implements the WELL44497b pseudo-random number generator
|
||||
* from François Panneton, Pierre L'Ecuyer and Makoto Matsumoto.
|
||||
* <p>
|
||||
* This generator is described in a paper by François Panneton,
|
||||
* Pierre L'Ecuyer and Makoto Matsumoto <a
|
||||
* href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng.pdf">Improved
|
||||
* Long-Period Generators Based on Linear Recurrences Modulo 2</a> ACM
|
||||
* Transactions on Mathematical Software, 32, 1 (2006). The errata for the paper
|
||||
* are in <a href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng-errata.txt">wellrng-errata.txt</a>.</p>
|
||||
*
|
||||
* @see <a href="http://www.iro.umontreal.ca/~panneton/WELLRNG.html">WELL Random number generator</a>
|
||||
* @since 2.2
|
||||
*/
|
||||
public class Well44497b extends AbstractWell {
|
||||
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 20150223L;
|
||||
|
||||
/** Number of bits in the pool. */
|
||||
private static final int K = 44497;
|
||||
|
||||
/** First parameter of the algorithm. */
|
||||
private static final int M1 = 23;
|
||||
|
||||
/** Second parameter of the algorithm. */
|
||||
private static final int M2 = 481;
|
||||
|
||||
/** Third parameter of the algorithm. */
|
||||
private static final int M3 = 229;
|
||||
|
||||
/** The indirection index table. */
|
||||
private static final IndexTable TABLE = new IndexTable(K, M1, M2, M3);
|
||||
|
||||
/** Creates a new random number generator.
|
||||
* <p>The instance is initialized using the current time as the
|
||||
* seed.</p>
|
||||
*/
|
||||
public Well44497b() {
|
||||
super(K);
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using a single int seed.
|
||||
* @param seed the initial seed (32 bits integer)
|
||||
*/
|
||||
public Well44497b(int seed) {
|
||||
super(K, seed);
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using an int array seed.
|
||||
* @param seed the initial seed (32 bits integers array), if null
|
||||
* the seed of the generator will be related to the current time
|
||||
*/
|
||||
public Well44497b(int[] seed) {
|
||||
super(K, seed);
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using a single long seed.
|
||||
* @param seed the initial seed (64 bits integer)
|
||||
*/
|
||||
public Well44497b(long seed) {
|
||||
super(K, seed);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected int next(final int bits) {
|
||||
|
||||
// compute raw value given by WELL44497a generator
|
||||
// which is NOT maximally-equidistributed
|
||||
final int indexRm1 = TABLE.getIndexPred(index);
|
||||
final int indexRm2 = TABLE.getIndexPred2(index);
|
||||
|
||||
final int v0 = v[index];
|
||||
final int vM1 = v[TABLE.getIndexM1(index)];
|
||||
final int vM2 = v[TABLE.getIndexM2(index)];
|
||||
final int vM3 = v[TABLE.getIndexM3(index)];
|
||||
|
||||
// the values below include the errata of the original article
|
||||
final int z0 = (0xFFFF8000 & v[indexRm1]) ^ (0x00007FFF & v[indexRm2]);
|
||||
final int z1 = (v0 ^ (v0 << 24)) ^ (vM1 ^ (vM1 >>> 30));
|
||||
final int z2 = (vM2 ^ (vM2 << 10)) ^ (vM3 << 26);
|
||||
final int z3 = z1 ^ z2;
|
||||
final int z2Prime = ((z2 << 9) ^ (z2 >>> 23)) & 0xfbffffff;
|
||||
final int z2Second = ((z2 & 0x00020000) != 0) ? (z2Prime ^ 0xb729fcec) : z2Prime;
|
||||
int z4 = z0 ^ (z1 ^ (z1 >>> 20)) ^ z2Second ^ z3;
|
||||
|
||||
v[index] = z3;
|
||||
v[indexRm1] = z4;
|
||||
v[indexRm2] &= 0xFFFF8000;
|
||||
index = indexRm1;
|
||||
|
||||
// add Matsumoto-Kurita tempering
|
||||
// to get a maximally-equidistributed generator
|
||||
z4 ^= (z4 << 7) & 0x93dd1400;
|
||||
z4 ^= (z4 << 15) & 0xfa118000;
|
||||
|
||||
return z4 >>> (32 - bits);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
|
||||
/** This class implements the WELL512a pseudo-random number generator
|
||||
* from François Panneton, Pierre L'Ecuyer and Makoto Matsumoto.
|
||||
* <p>
|
||||
* This generator is described in a paper by François Panneton,
|
||||
* Pierre L'Ecuyer and Makoto Matsumoto <a
|
||||
* href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng.pdf">Improved
|
||||
* Long-Period Generators Based on Linear Recurrences Modulo 2</a> ACM
|
||||
* Transactions on Mathematical Software, 32, 1 (2006). The errata for the paper
|
||||
* are in <a href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng-errata.txt">wellrng-errata.txt</a>.</p>
|
||||
*
|
||||
* @see <a href="http://www.iro.umontreal.ca/~panneton/WELLRNG.html">WELL Random number generator</a>
|
||||
* @since 2.2
|
||||
*/
|
||||
public class Well512a extends AbstractWell {
|
||||
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 20150223L;
|
||||
|
||||
/** Number of bits in the pool. */
|
||||
private static final int K = 512;
|
||||
|
||||
/** First parameter of the algorithm. */
|
||||
private static final int M1 = 13;
|
||||
|
||||
/** Second parameter of the algorithm. */
|
||||
private static final int M2 = 9;
|
||||
|
||||
/** Third parameter of the algorithm. */
|
||||
private static final int M3 = 5;
|
||||
|
||||
/** The indirection index table. */
|
||||
private static final IndexTable TABLE = new IndexTable(K, M1, M2, M3);
|
||||
|
||||
/** Creates a new random number generator.
|
||||
* <p>The instance is initialized using the current time as the
|
||||
* seed.</p>
|
||||
*/
|
||||
public Well512a() {
|
||||
super(K);
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using a single int seed.
|
||||
* @param seed the initial seed (32 bits integer)
|
||||
*/
|
||||
public Well512a(int seed) {
|
||||
super(K, seed);
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using an int array seed.
|
||||
* @param seed the initial seed (32 bits integers array), if null
|
||||
* the seed of the generator will be related to the current time
|
||||
*/
|
||||
public Well512a(int[] seed) {
|
||||
super(K, seed);
|
||||
}
|
||||
|
||||
/** Creates a new random number generator using a single long seed.
|
||||
* @param seed the initial seed (64 bits integer)
|
||||
*/
|
||||
public Well512a(long seed) {
|
||||
super(K, seed);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected int next(final int bits) {
|
||||
|
||||
final int indexRm1 = TABLE.getIndexPred(index);
|
||||
|
||||
final int vi = v[index];
|
||||
final int vi1 = v[TABLE.getIndexM1(index)];
|
||||
final int vi2 = v[TABLE.getIndexM2(index)];
|
||||
final int z0 = v[indexRm1];
|
||||
|
||||
// the values below include the errata of the original article
|
||||
final int z1 = (vi ^ (vi << 16)) ^ (vi1 ^ (vi1 << 15));
|
||||
final int z2 = vi2 ^ (vi2 >>> 11);
|
||||
final int z3 = z1 ^ z2;
|
||||
final int z4 = (z0 ^ (z0 << 2)) ^ (z1 ^ (z1 << 18)) ^ (z2 << 28) ^ (z3 ^ ((z3 << 5) & 0xda442d24));
|
||||
|
||||
v[index] = z3;
|
||||
v[indexRm1] = z4;
|
||||
index = indexRm1;
|
||||
|
||||
return z4 >>> (32 - bits);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -15,118 +15,18 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* <p>Random Data Generation</p>
|
||||
*
|
||||
* <p>Random number and random data generators.</p>
|
||||
* <p>Commons-math provides a few pseudo random number generators. The top level interface is RandomGenerator.
|
||||
* It is implemented by three classes:
|
||||
* <ul>
|
||||
* <li>{@link org.apache.commons.math4.random.JDKRandomGenerator JDKRandomGenerator}
|
||||
* that extends the JDK provided generator</li>
|
||||
* <li>AbstractRandomGenerator as a helper for users generators</li>
|
||||
* <li>BitStreamGenerator which is an abstract class for several generators and
|
||||
* which in turn is extended by:
|
||||
* <ul>
|
||||
* <li>{@link org.apache.commons.math4.random.MersenneTwister MersenneTwister}</li>
|
||||
* <li>{@link org.apache.commons.math4.random.Well512a Well512a}</li>
|
||||
* <li>{@link org.apache.commons.math4.random.Well1024a Well1024a}</li>
|
||||
* <li>{@link org.apache.commons.math4.random.Well19937a Well19937a}</li>
|
||||
* <li>{@link org.apache.commons.math4.random.Well19937c Well19937c}</li>
|
||||
* <li>{@link org.apache.commons.math4.random.Well44497a Well44497a}</li>
|
||||
* <li>{@link org.apache.commons.math4.random.Well44497b Well44497b}</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* The JDK provided generator is a simple one that can be used only for very simple needs.
|
||||
* The Mersenne Twister is a fast generator with very good properties well suited for
|
||||
* Monte-Carlo simulation. It is equidistributed for generating vectors up to dimension 623
|
||||
* and has a huge period: 2<sup>19937</sup> - 1 (which is a Mersenne prime). This generator
|
||||
* is described in a paper by Makoto Matsumoto and Takuji Nishimura in 1998: <a
|
||||
* href="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/ARTICLES/mt.pdf">Mersenne Twister:
|
||||
* A 623-Dimensionally Equidistributed Uniform Pseudo-Random Number Generator</a>, ACM
|
||||
* Transactions on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3--30.
|
||||
* The WELL generators are a family of generators with period ranging from 2<sup>512</sup> - 1
|
||||
* to 2<sup>44497</sup> - 1 (this last one is also a Mersenne prime) with even better properties
|
||||
* than Mersenne Twister. These generators are described in a paper by François Panneton,
|
||||
* Pierre L'Ecuyer and Makoto Matsumoto <a
|
||||
* href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng.pdf">Improved Long-Period
|
||||
* Generators Based on Linear Recurrences Modulo 2</a> ACM Transactions on Mathematical Software,
|
||||
* 32, 1 (2006). The errata for the paper are in <a
|
||||
* href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng-errata.txt">wellrng-errata.txt</a>.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* For simple sampling, any of these generators is sufficient. For Monte-Carlo simulations the
|
||||
* JDK generator does not have any of the good mathematical properties of the other generators,
|
||||
* so it should be avoided. The Mersenne twister and WELL generators have equidistribution properties
|
||||
* proven according to their bits pool size which is directly linked to their period (all of them
|
||||
* have maximal period, i.e. a generator with size n pool has a period 2<sup>n</sup>-1). They also
|
||||
* have equidistribution properties for 32 bits blocks up to s/32 dimension where s is their pool size.
|
||||
* So WELL19937c for exemple is equidistributed up to dimension 623 (19937/32). This means a Monte-Carlo
|
||||
* simulation generating a vector of n variables at each iteration has some guarantees on the properties
|
||||
* of the vector as long as its dimension does not exceed the limit. However, since we use bits from two
|
||||
* successive 32 bits generated integers to create one double, this limit is smaller when the variables are
|
||||
* of type double. so for Monte-Carlo simulation where less the 16 doubles are generated at each round,
|
||||
* WELL1024 may be sufficient. If a larger number of doubles are needed a generator with a larger pool
|
||||
* would be useful.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* The WELL generators are more modern then MersenneTwister (the paper describing than has been published
|
||||
* in 2006 instead of 1998) and fix some of its (few) drawbacks. If initialization array contains many
|
||||
* zero bits, MersenneTwister may take a very long time (several hundreds of thousands of iterations to
|
||||
* reach a steady state with a balanced number of zero and one in its bits pool). So the WELL generators
|
||||
* are better to <i>escape zeroland</i> as explained by the WELL generators creators. The Well19937a and
|
||||
* Well44497a generator are not maximally equidistributed (i.e. there are some dimensions or bits blocks
|
||||
* size for which they are not equidistributed). The Well512a, Well1024a, Well19937c and Well44497b are
|
||||
* maximally equidistributed for blocks size up to 32 bits (they should behave correctly also for double
|
||||
* based on more than 32 bits blocks, but equidistribution is not proven at these blocks sizes).
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* The MersenneTwister generator uses a 624 elements integer array, so it consumes less than 2.5 kilobytes.
|
||||
* The WELL generators use 6 integer arrays with a size equal to the pool size, so for example the
|
||||
* WELL44497b generator uses about 33 kilobytes. This may be important if a very large number of
|
||||
* generator instances were used at the same time.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* All generators are quite fast. As an example, here are some comparisons, obtained on a 64 bits JVM on a
|
||||
* linux computer with a 2008 processor (AMD phenom Quad 9550 at 2.2 GHz). The generation rate for
|
||||
* MersenneTwister was about 27 millions doubles per second (remember we generate two 32 bits integers for
|
||||
* each double). Generation rates for other PRNG, relative to MersenneTwister:
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* <table border="1" align="center">
|
||||
* <tr BGCOLOR="#CCCCFF"><td colspan="2"><font size="+2">Example of performances</font></td></tr>
|
||||
* <tr BGCOLOR="#EEEEFF"><font size="+1"><td>Name</td><td>generation rate (relative to MersenneTwister)</td></font></tr>
|
||||
* <tr><td>{@link org.apache.commons.math4.random.MersenneTwister MersenneTwister}</td><td>1</td></tr>
|
||||
* <tr><td>{@link org.apache.commons.math4.random.JDKRandomGenerator JDKRandomGenerator}</td><td>between 0.96 and 1.16</td></tr>
|
||||
* <tr><td>{@link org.apache.commons.math4.random.Well512a Well512a}</td><td>between 0.85 and 0.88</td></tr>
|
||||
* <tr><td>{@link org.apache.commons.math4.random.Well1024a Well1024a}</td><td>between 0.63 and 0.73</td></tr>
|
||||
* <tr><td>{@link org.apache.commons.math4.random.Well19937a Well19937a}</td><td>between 0.70 and 0.71</td></tr>
|
||||
* <tr><td>{@link org.apache.commons.math4.random.Well19937c Well19937c}</td><td>between 0.57 and 0.71</td></tr>
|
||||
* <tr><td>{@link org.apache.commons.math4.random.Well44497a Well44497a}</td><td>between 0.69 and 0.71</td></tr>
|
||||
* <tr><td>{@link org.apache.commons.math4.random.Well44497b Well44497b}</td><td>between 0.65 and 0.71</td></tr>
|
||||
* </table>
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* So for most simulation problems, the better generators like {@link
|
||||
* org.apache.commons.math4.random.Well19937c Well19937c} and {@link
|
||||
* org.apache.commons.math4.random.Well44497b Well44497b} are probably very good choices.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* Note that <em>none</em> of these generators are suitable for cryptography. They are devoted
|
||||
* to simulation, and to generate very long series with strong properties on the series as a whole
|
||||
* (equidistribution, no correlation ...). They do not attempt to create small series but with
|
||||
* very strong properties of unpredictability as needed in cryptography.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* Some of the utilities in this package use the pseudo-random number
|
||||
* generators defined in package {@link org.apache.commons.math4.rng}
|
||||
* to provide {@link org.apache.commons.math4.random.RandomUtils.DataGenerator
|
||||
* higher level functionality} (such as random strings) based on an underlying
|
||||
* source of randomness that provides sequences of uniformly distributed integers.
|
||||
* </p>
|
||||
* <p>
|
||||
* Others are sources of pseudo-randomness that directly produce "compound" types
|
||||
* such as {@link org.apache.commons.math4.random.RandomVectorGenerator random vectors}.
|
||||
* </p>
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.apache.commons.math4.rng.internal.source64.TwoCmres;
|
|||
* </code></pre>
|
||||
* or
|
||||
* <pre><code>
|
||||
* final int[] seed = new int[] { 196, 9, 0, 226 };
|
||||
* final int[] seed = new int[] { 196, 9, 0, 226 };
|
||||
* UniformRandomProvider rng = RandomSource.create(RandomSource.MT, seed);
|
||||
* </code></pre>
|
||||
* or
|
||||
|
@ -44,8 +44,8 @@ import org.apache.commons.math4.rng.internal.source64.TwoCmres;
|
|||
* (optional) seed.
|
||||
* <br>
|
||||
* In the first form, a random seed will be {@link SeedFactory generated
|
||||
* automatically}; the random seed generation step is explicit in the
|
||||
* third form.
|
||||
* automatically}; in the second form, a fixed seed is used; a random seed
|
||||
* is explicitly generated in the third form.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
|
@ -68,22 +68,22 @@ import org.apache.commons.math4.rng.internal.source64.TwoCmres;
|
|||
* internal state.
|
||||
* <br>
|
||||
* When the seed value passed by the caller is of the native type, it is
|
||||
* expected that the sequences produced will be the same as those
|
||||
* produced by other implementations of the algorithm.
|
||||
* expected that the sequences produced will be identical to those
|
||||
* produced by other implementations of the same reference algorithm.
|
||||
* <br>
|
||||
* However, when the seed value passed by the caller is not of the native
|
||||
* type, a transformation is performed by this library and the resulting
|
||||
* native type value will <i>not</i> contain more information than the
|
||||
* original seed value.
|
||||
* If the algorithm's native type is "simpler" than the type passed by
|
||||
* the caller, then some (unuse) information will even be lost.
|
||||
* the caller, then some (unused) information will even be lost.
|
||||
* <br>
|
||||
* The transformation from non-native to native seed type is arbitrary,
|
||||
* as long as it does not reduce the amount of information required by
|
||||
* the algorithm to initialize its state.
|
||||
* The consequence of the transformation is that the sequences produced
|
||||
* by this library may not be the same as the sequences produced by other
|
||||
* implementations of the same algorithm!
|
||||
* The consequence of the transformation is that sequences produced
|
||||
* by this library may <i>not</i> be the same as the sequences produced
|
||||
* by other implementations of the same algorithm!
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
|
@ -93,11 +93,12 @@ import org.apache.commons.math4.rng.internal.source64.TwoCmres;
|
|||
* generators factory method}.
|
||||
* <br>
|
||||
* Although the seed-generating methods defined in this class will likely
|
||||
* return different values for all calls, there is no guarantee that the
|
||||
* produced seed will result always in a "good" sequence of numbers, even
|
||||
* if the generator is good.
|
||||
* return different values each time they are called, there is no guarantee
|
||||
* that the resulting "seed" will always generate a <i>good</i> (i.e.
|
||||
* sufficiently uniformly random for the intended purpose) sequence of
|
||||
* numbers, even if the generator is good!
|
||||
* The only way to ensure that the selected seed will make the generator
|
||||
* produce a "good" sequence is to submit that sequence to a series of
|
||||
* produce a good sequence is to submit that sequence to a series of
|
||||
* stringent tests, as provided by tools such as
|
||||
* <a href="http://www.phy.duke.edu/~rgb/General/dieharder.php">dieharder</a>
|
||||
* or <a href="http://simul.iro.umontreal.ca/testu01/tu01.html">TestU01</a>.
|
||||
|
@ -133,7 +134,7 @@ import org.apache.commons.math4.rng.internal.source64.TwoCmres;
|
|||
* used for {@link #restoreState(UniformRandomProvider,State) restoring}
|
||||
* a generator (of the same type) to an identical state (e.g. to allow
|
||||
* persistent storage, or to continue a sequence from where the original
|
||||
* instance left off.).
|
||||
* instance left off).
|
||||
* </p>
|
||||
*
|
||||
* @since 4.0
|
||||
|
@ -252,11 +253,11 @@ public enum RandomSource {
|
|||
* <p>
|
||||
* Example of usage:
|
||||
* <pre><code>
|
||||
* UniformRandomProvider rng = RandomSource.create(Source.MT);
|
||||
* UniformRandomProvider rng = RandomSource.create(RandomSource.MT);
|
||||
* </code></pre>
|
||||
* </p>
|
||||
*
|
||||
* @param source {@link RandomSource RNG type}.
|
||||
* @param source RNG type.
|
||||
* @return the RNG.
|
||||
*/
|
||||
public static UniformRandomProvider create(RandomSource source) {
|
||||
|
@ -269,7 +270,7 @@ public enum RandomSource {
|
|||
* <p>
|
||||
* Example of usage:
|
||||
* <pre><code>
|
||||
* UniformRandomProvider rng = RandomSource.create(Source.TWO_CMRES_SELECT, 26219, 6, 9);
|
||||
* UniformRandomProvider rng = RandomSource.create(RandomSource.TWO_CMRES_SELECT, 26219, 6, 9);
|
||||
* </code></pre>
|
||||
* </p>
|
||||
*
|
||||
|
@ -303,7 +304,7 @@ public enum RandomSource {
|
|||
* </li>
|
||||
* </p>
|
||||
*
|
||||
* @param source {@link RandomSource RNG type}.
|
||||
* @param source RNG type.
|
||||
* @param seed Seed value. It can be {@code null} (in which case a
|
||||
* random value will be used).
|
||||
* @param data Additional arguments to the implementation's constructor.
|
||||
|
@ -358,7 +359,7 @@ public enum RandomSource {
|
|||
* This parameter must have been obtained by a call to
|
||||
* {@link #saveState(UniformRandomProvider) saveState(rng)}
|
||||
* where {@code rng} is either the same object as {@code provider},
|
||||
* or an object of the same concrete type.
|
||||
* or an object of the exact same class.
|
||||
* @throws MathUnsupportedOperationException if the {@code provider} is
|
||||
* not an object created by this factory or the underlying source of
|
||||
* randomness does not support this functionality.
|
||||
|
|
|
@ -31,13 +31,15 @@ import org.apache.commons.math4.util.FastMath;
|
|||
|
||||
|
||||
/**
|
||||
* <p> Ranking based on the natural ordering on doubles.</p>
|
||||
* Ranking based on the natural ordering on doubles.
|
||||
*
|
||||
* <p>NaNs are treated according to the configured {@link NaNStrategy} and ties
|
||||
* are handled using the selected {@link TiesStrategy}.
|
||||
* Configuration settings are supplied in optional constructor arguments.
|
||||
* Defaults are {@link NaNStrategy#FAILED} and {@link TiesStrategy#AVERAGE},
|
||||
* respectively. When using {@link TiesStrategy#RANDOM}, a
|
||||
* {@link RandomGenerator} may be supplied as a constructor argument.</p>
|
||||
* {@link UniformRandomProvider random generator} may be supplied as a
|
||||
* constructor argument.</p>
|
||||
* <p>Examples:
|
||||
* <table border="1" cellpadding="3">
|
||||
* <tr><th colspan="3">
|
||||
|
@ -127,7 +129,7 @@ public class NaturalRanking implements RankingAlgorithm {
|
|||
|
||||
/**
|
||||
* Create a NaturalRanking with TiesStrategy.RANDOM and the given
|
||||
* RandomGenerator as the source of random data.
|
||||
* random generator as the source of random data.
|
||||
*
|
||||
* @param randomGenerator source of random data
|
||||
*/
|
||||
|
|
|
@ -28,9 +28,11 @@
|
|||
|
||||
<section name="2 Data Generation">
|
||||
|
||||
<subsection name="2.1 Overview" href="overview">
|
||||
<subsection name="2.1 Overview"
|
||||
href="overview">
|
||||
<p>
|
||||
The Commons Math random package includes utilities for
|
||||
The Commons Math <a href="../apidocs/org/apache/commons/math4/random/package-summary.html">o.a.c.m.random</a>
|
||||
package includes utilities for
|
||||
<ul>
|
||||
<li>generating random numbers</li>
|
||||
<li>generating random vectors</li>
|
||||
|
@ -44,37 +46,35 @@
|
|||
histograms</li>
|
||||
</ul></p>
|
||||
<p>
|
||||
The source of random data used by the data generation utilities is
|
||||
pluggable. By default, the JDK-supplied PseudoRandom Number Generator
|
||||
(PRNG) is used, but alternative generators can be "plugged in" using an
|
||||
adaptor framework, which provides a generic facility for replacing
|
||||
<code>java.util.Random</code> with an alternative PRNG. Other very
|
||||
good PRNG suitable for Monte-Carlo analysis (but <strong>not</strong>
|
||||
for cryptography) provided by the library are the Mersenne twister from
|
||||
Makoto Matsumoto and Takuji Nishimura and the more recent WELL generators
|
||||
(Well Equidistributed Long-period Linear) from François Panneton, Pierre
|
||||
L'Ecuyer and Makoto Matsumoto.
|
||||
These utilities rely on an underlying "source of randomness", which in most
|
||||
cases is a pseudo-random number generator (PRNG) that produces sequences
|
||||
of numbers that are uniformly distributed within their range.
|
||||
Commons Math provides many PRNG implementations that share a common
|
||||
interface:
|
||||
<a href="../apidocs/org/apache/commons/math4/rng/UniformRandomProvider.html">
|
||||
UniformRandomProvider</a> (for more details about this interface and the
|
||||
available RNG algorithms, please refer to the Javadoc of package
|
||||
<a href="../apidocs/org/apache/commons/math4/rng/package-summary.html">
|
||||
org.apache.commons.math4.rng</a> and <a href="../userguide/rng.html">this section</a>
|
||||
of the userguide.
|
||||
</p>
|
||||
<p>
|
||||
Sections 2.2-2.6 below show how to use the commons math API to generate
|
||||
different kinds of random data. The examples all use the default
|
||||
JDK-supplied PRNG. PRNG pluggability is covered in 2.7. The only
|
||||
modification required to the examples to use alternative PRNGs is to
|
||||
replace the argumentless constructor calls with invocations including
|
||||
a <code>RandomGenerator</code> instance as a parameter.
|
||||
</p>
|
||||
A PRNG algorithm is often deterministic, i.e. it produces the same sequence
|
||||
when initialized with the same "seed".
|
||||
This property is important for some applications like Monte-Carlo simulations,
|
||||
but makes such a PRNG often unsuitable for cryptographic purposes.
|
||||
</p>
|
||||
</subsection>
|
||||
|
||||
<subsection name="2.2 Random numbers" href="deviates">
|
||||
<p>
|
||||
The <a href="../apidocs/org/apache/commons/math4/random/RandomDataGenerator.html">
|
||||
RandomDataGenerator</a> class implements methods for generating random sequences
|
||||
of numbers. The API contracts of these methods use the following concepts:
|
||||
<subsection name="2.2 Random Deviates"
|
||||
href="deviates">
|
||||
<p>
|
||||
<dl>
|
||||
<dt>Random sequence of numbers from a probability distribution</dt>
|
||||
<dd>There is no such thing as a single "random number." What can be
|
||||
<dd>
|
||||
There is no such thing as a single "random number." What can be
|
||||
generated are <i>sequences</i> of numbers that appear to be random. When
|
||||
using the built-in JDK function <code>Math.random(),</code> sequences of
|
||||
using the built-in JDK function <code>Math.random()</code>, sequences of
|
||||
values generated follow the
|
||||
<a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda3662.htm">
|
||||
Uniform Distribution</a>, which means that the values are evenly spread
|
||||
|
@ -85,84 +85,46 @@
|
|||
probability distribution</a> basically amounts to asserting that different
|
||||
ranges in the set of possible values of a random variable have
|
||||
different probabilities of containing the value. Commons Math supports
|
||||
generating random sequences from each of the distributions in the
|
||||
generating random sequences from each of the distributions defined in the
|
||||
<a href="../apidocs/org/apache/commons/math4/distribution/package-summary.html">
|
||||
distributions</a> package.
|
||||
The javadoc for the <code>nextXxx</code> methods in
|
||||
<a href="../apidocs/org/apache/commons/math4/random/RandomDataGenerator.html">
|
||||
RandomDataGenerator</a> describes the algorithms used to generate
|
||||
random deviates.
|
||||
o.a.c.m.distribution</a> package.
|
||||
Please refer to the <a href="../distribution.html">specific documentation</a>
|
||||
for more details.
|
||||
</dd>
|
||||
|
||||
<dt>Cryptographically secure random sequences</dt>
|
||||
<dd>It is possible for a sequence of numbers to appear random, but
|
||||
<dd>
|
||||
It is possible for a sequence of numbers to appear random, but
|
||||
nonetheless to be predictable based on the algorithm used to generate the
|
||||
sequence. If in addition to randomness, strong unpredictability is
|
||||
required, it is best to use a
|
||||
<a href="http://www.wikipedia.org/wiki/Cryptographically_secure_pseudo-random_number_generator">
|
||||
secure random number generator</a> to generate values (or strings). The
|
||||
nextSecureXxx methods implemented by <code>RandomDataGenerator</code>
|
||||
use the JDK <code>SecureRandom</code> PRNG to generate cryptographically
|
||||
secure sequences. The <code>setSecureAlgorithm</code> method allows you to
|
||||
change the underlying PRNG. These methods are <strong>much slower</strong> than
|
||||
the corresponding "non-secure" versions, so they should only be used when cryptographic
|
||||
security is required. The <code>ISAACRandom</code> class implements a fast
|
||||
cryptographically secure pseudorandom number generator.</dd>
|
||||
<dt>Seeding pseudo-random number generators</dt>
|
||||
<dd>By default, the implementation provided in <code>RandomDataGenerator</code>
|
||||
uses the JDK-provided PRNG. Like most other PRNGs, the JDK generator
|
||||
generates sequences of random numbers based on an initial "seed value."
|
||||
For the non-secure methods, starting with the same seed always produces the
|
||||
same sequence of values. Secure sequences started with the same seeds will
|
||||
diverge. When a new <code>RandomDataGenerator</code> is created, the underlying
|
||||
random number generators are <strong>not</strong> initialized. The first
|
||||
call to a data generation method, or to a <code>reSeed()</code> method
|
||||
initializes the appropriate generator. If you do not explicitly seed the
|
||||
generator, it is by default seeded with the current time in milliseconds.
|
||||
Therefore, to generate sequences of random data values, you should always
|
||||
instantiate <strong>one</strong> <code> RandomDataGenerator</code> and use it
|
||||
repeatedly instead of creating new instances for subsequent values in the
|
||||
sequence. For example, the following will generate a random sequence of 50
|
||||
long integers between 1 and 1,000,000, using the current time in
|
||||
milliseconds as the seed for the JDK PRNG:
|
||||
secure random number generator</a> to generate values (or strings).
|
||||
|
||||
Most PRNG implemented in this library are not secure in that sense, except
|
||||
perhaps the <a href="../apidocs/org/apache/commons/math4/rng/internal/source32/ISAACRandom.html">
|
||||
ISAAC generator</a>.
|
||||
An alternative is to use an instance of the JDK-provided <code>SecureRandom</code>
|
||||
generator.
|
||||
In general, such secure generator produce sequence based on a source of
|
||||
true randomness, and sequences started with the same seed will diverge.
|
||||
|
||||
The <a href="../apidocs/org/apache/commons/math4/random/RandomUtils.html">RandomUtils</a>
|
||||
class provides a "factory" method to wrap <code>java.util.Random</code> or
|
||||
<code>java.security.SecureRandom</code> instances in an object that implements
|
||||
the <a href="../apidocs/org/apache/commons/math4/rng/UniformRandomProvider.html">
|
||||
UniformRandomProvider</a> interface:
|
||||
<source>
|
||||
RandomDataGenerator randomData = new RandomDataGenerator();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
value = randomData.nextLong(1, 1000000);
|
||||
}
|
||||
</source>
|
||||
The following will not in general produce a good random sequence, since the
|
||||
PRNG is reseeded each time through the loop with the current time in
|
||||
milliseconds:
|
||||
<source>
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
RandomDataGenerator randomData = new RandomDataGenerator();
|
||||
value = randomData.nextLong(1, 1000000);
|
||||
}
|
||||
</source>
|
||||
The following will produce the same random sequence each time it is
|
||||
executed:
|
||||
<source>
|
||||
RandomDataGenerator randomData = new RandomDataGenerator();
|
||||
randomData.reSeed(1000);
|
||||
for (int i = 0; i = 1000; i++) {
|
||||
value = randomData.nextLong(1, 1000000);
|
||||
}
|
||||
</source>
|
||||
The following will produce a different random sequence each time it is
|
||||
executed.
|
||||
<source>
|
||||
RandomDataGenerator randomData = new RandomDataGenerator();
|
||||
randomData.reSeedSecure(1000);
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
value = randomData.nextSecureLong(1, 1000000);
|
||||
}
|
||||
</source>
|
||||
</dd></dl>
|
||||
</p>
|
||||
UniformRandomProvider rg = RandomUtils.asUniformRandomProvider(new java.security.SecureRandom());
|
||||
</source>
|
||||
</dd>
|
||||
</dl>
|
||||
</p>
|
||||
</subsection>
|
||||
|
||||
<subsection name="2.3 Random Vectors" href="vectors">
|
||||
<p>
|
||||
<subsection name="2.3 Random Vectors"
|
||||
href="vectors">
|
||||
<p>
|
||||
Some algorithms require random vectors instead of random scalars. When the
|
||||
components of these vectors are uncorrelated, they may be generated simply
|
||||
one at a time and packed together in the vector. The <a
|
||||
|
@ -175,21 +137,26 @@ for (int i = 0; i < 1000; i++) {
|
|||
case, the user must set up a complete covariance matrix instead of a simple
|
||||
standard deviations vector. This matrix gathers both the variance and the
|
||||
correlation information of the probability law.
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
The main use for correlated random vector generation is for Monte-Carlo
|
||||
simulation of physical problems with several variables, for example to
|
||||
generate error vectors to be added to a nominal vector. A particularly
|
||||
common case is when the generated vector should be drawn from a <a
|
||||
href="http://en.wikipedia.org/wiki/Multivariate_normal_distribution">
|
||||
Multivariate Normal Distribution</a>.
|
||||
</p>
|
||||
<p><dl>
|
||||
</p>
|
||||
|
||||
<p><dl>
|
||||
<dt>Generating random vectors from a bivariate normal distribution</dt><dd>
|
||||
<source>
|
||||
// Create and seed a RandomGenerator (could use any of the generators in the random package here)
|
||||
RandomGenerator rg = new JDKRandomGenerator();
|
||||
rg.setSeed(17399225432l); // Fixed seed means same results every time
|
||||
// Import common PRNG interface and factory class that instantiates the PRNG.
|
||||
import org.apache.commons.math4.rng.UniformRandomProvider;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
|
||||
// Create (and possibly seed) a PRNG (could use any of the CM-provided generators)
|
||||
long seed = 17399225432L; // Fixed seed means same results every time
|
||||
UniformRandomProvider rg = RandomSource.create(RandomSource.MT, seed);
|
||||
|
||||
// Create a GassianRandomGenerator using rg as its source of randomness
|
||||
GaussianRandomGenerator rawGenerator = new GaussianRandomGenerator(rg);
|
||||
|
@ -201,10 +168,13 @@ CorrelatedRandomVectorGenerator generator =
|
|||
// Use the generator to generate correlated vectors
|
||||
double[] randomVector = generator.nextVector();
|
||||
... </source>
|
||||
The <code>mean</code> argument is a double[] array holding the means of the random vector
|
||||
components. In the bivariate case, it must have length 2. The <code>covariance</code> argument
|
||||
is a RealMatrix, which needs to be 2 x 2. The main diagonal elements are the
|
||||
variances of the vector components and the off-diagonal elements are the covariances.
|
||||
|
||||
The <code>mean</code> argument is a <code>double[]</code> array holding the means
|
||||
of the random vector components. In the bivariate case, it must have length 2.
|
||||
The <code>covariance</code> argument is a <code>RealMatrix</code>, which has to
|
||||
be 2 x 2.
|
||||
The main diagonal elements are the variances of the vector components and the
|
||||
off-diagonal elements are the covariances.
|
||||
For example, if the means are 1 and 2 respectively, and the desired standard deviations
|
||||
are 3 and 4, respectively, then we need to use
|
||||
<source>
|
||||
|
@ -214,9 +184,10 @@ RealMatrix covariance = MatrixUtils.createRealMatrix(cov); </source>
|
|||
where c is the desired covariance. If you are starting with a desired correlation,
|
||||
you need to translate this to a covariance by multiplying it by the product of the
|
||||
standard deviations. For example, if you want to generate data that will give Pearson's
|
||||
R of 0.5, you would use c = 3 * 4 * .5 = 6.
|
||||
</dd></dl></p>
|
||||
<p>
|
||||
R of 0.5, you would use c = 3 * 4 * 0.5 = 6.
|
||||
</dd>
|
||||
</dl></p>
|
||||
<p>
|
||||
In addition to multivariate normal distributions, correlated vectors from multivariate uniform
|
||||
distributions can be generated by creating a
|
||||
<a href="../apidocs/org/apache/commons/math4/random/UniformRandomGenerator.html">UniformRandomGenerator</a>
|
||||
|
@ -224,8 +195,9 @@ RealMatrix covariance = MatrixUtils.createRealMatrix(cov); </source>
|
|||
<code>GaussianRandomGenerator</code> above. More generally, any
|
||||
<a href="../apidocs/org/apache/commons/math4/random/NormalizedRandomGenerator.html">NormalizedRandomGenerator</a>
|
||||
may be used.
|
||||
</p>
|
||||
<p><dl>
|
||||
</p>
|
||||
|
||||
<p><dl>
|
||||
<dt>Low discrepancy sequences</dt>
|
||||
<dd>
|
||||
There exist several quasi-random sequences with the property that for all values of N, the subsequence
|
||||
|
@ -234,8 +206,10 @@ RealMatrix covariance = MatrixUtils.createRealMatrix(cov); </source>
|
|||
is completely deterministic), their unique properties give them an important advantage for quasi-Monte Carlo simulations.<br/>
|
||||
Currently, the following low-discrepancy sequences are supported:
|
||||
<ul>
|
||||
<li><a href="../apidocs/org/apache/commons/math4/random/SobolSequenceGenerator.html">Sobol sequence</a> (pre-configured up to dimension 1000)</li>
|
||||
<li><a href="../apidocs/org/apache/commons/math4/random/HaltonSequenceGenerator.html">Halton sequence</a> (pre-configured up to dimension 40)</li>
|
||||
<li><a href="../apidocs/org/apache/commons/math4/random/SobolSequenceGenerator.html">
|
||||
Sobol sequence</a> (pre-configured up to dimension 1000)</li>
|
||||
<li><a href="../apidocs/org/apache/commons/math4/random/HaltonSequenceGenerator.html">
|
||||
Halton sequence</a> (pre-configured up to dimension 40)</li>
|
||||
</ul>
|
||||
<source>
|
||||
// Create a Sobol sequence generator for 2-dimensional vectors
|
||||
|
@ -244,319 +218,87 @@ RandomVectorGenerator generator = new SobolSequence(2);
|
|||
// Use the generator to generate vectors
|
||||
double[] randomVector = generator.nextVector();
|
||||
... </source>
|
||||
The figure below illustrates the unique properties of low-discrepancy sequences when generating N samples
|
||||
in the interval [0, 1]. Roughly speaking, such sequences "fill" the respective space more evenly which leads to faster convergence in
|
||||
quasi-Monte Carlo simulations.<br/>
|
||||
<img src="../images/userguide/low_discrepancy_sequences.png" alt="Comparison of low-discrepancy sequences"/>
|
||||
</dd></dl>
|
||||
</p>
|
||||
<p></p>
|
||||
|
||||
The figure below illustrates the unique properties of low-discrepancy sequences when
|
||||
generating N samples in the interval [0, 1]. Roughly speaking, such sequences "fill"
|
||||
the respective space more evenly which leads to faster convergence in quasi-Monte Carlo
|
||||
simulations.<br/>
|
||||
<img src="../images/userguide/low_discrepancy_sequences.png"
|
||||
alt="Comparison of low-discrepancy sequences"/>
|
||||
</dd>
|
||||
</dl></p>
|
||||
|
||||
</subsection>
|
||||
|
||||
<subsection name="2.4 Random Strings" href="strings">
|
||||
<subsection name="2.4 Random Strings"
|
||||
href="strings">
|
||||
<p>
|
||||
The methods <code>nextHexString</code> and <code>nextSecureHexString</code>
|
||||
can be used to generate random strings of hexadecimal characters. Both
|
||||
of these methods produce sequences of strings with good dispersion
|
||||
properties. The difference between the two methods is that the second is
|
||||
cryptographically secure. Specifically, the implementation of
|
||||
<code>nextHexString(n)</code> in <code>RandomDataGenerator</code> uses the
|
||||
following simple algorithm to generate a string of <code>n</code> hex digits:
|
||||
<ol>
|
||||
<li>n/2+1 binary bytes are generated using the underlying RandomGenerator</li>
|
||||
<li>Each binary byte is translated into 2 hex digits</li></ol>
|
||||
The <code>RandomDataGenerator</code> implementation of the "secure" version,
|
||||
<code>nextSecureHexString</code> generates hex characters in 40-byte
|
||||
"chunks" using a 3-step process:
|
||||
<ol>
|
||||
<li>20 random bytes are generated using the underlying
|
||||
<code>SecureRandom.</code></li>
|
||||
<li>SHA-1 hash is applied to yield a 20-byte binary digest.</li>
|
||||
<li>Each byte of the binary digest is converted to 2 hex digits</li></ol>
|
||||
Similarly to the secure random number generation methods,
|
||||
<code>nextSecureHexString</code> is <strong>much slower</strong> than
|
||||
the non-secure version. It should be used only for applications such as
|
||||
generating unique session or transaction ids where predictability of
|
||||
subsequent ids based on observation of previous values is a security
|
||||
concern. If all that is needed is an even distribution of hex characters
|
||||
in the generated strings, the non-secure method should be used.
|
||||
The method <code>nextHexString</code> in
|
||||
<a href="../apidocs/org/apache/commons/math4/random/RandomUtils.DataGenerator.html">
|
||||
RandomUtils.DataGenerator</a> can be used to generate random strings of
|
||||
hexadecimal characters.
|
||||
It produces sequences of strings with good dispersion properties.
|
||||
A string can be generated in two different ways, depending on the value
|
||||
of the boolean argument passed to the method (see the Javadoc for more
|
||||
details).
|
||||
</p>
|
||||
</subsection>
|
||||
|
||||
<subsection name="2.5 Random permutations, combinations, sampling"
|
||||
href="combinatorics">
|
||||
<p>
|
||||
<subsection name="2.5 Random Permutations, Combinations, Sampling"
|
||||
href="combinatorics">
|
||||
<p>
|
||||
To select a random sample of objects in a collection, you can use the
|
||||
<code>nextSample</code> method implemented by <code>RandomDataGenerator</code>.
|
||||
Specifically, if <code>c</code> is a collection containing at least
|
||||
<code>k</code> objects, and <code>randomData</code> is a
|
||||
<code>RandomDataGenerator</code> instance <code>randomData.nextSample(c, k)</code>
|
||||
will return an <code>object[]</code> array of length <code>k</code>
|
||||
consisting of elements randomly selected from the collection. If
|
||||
<code>c</code> contains duplicate references, there may be duplicate
|
||||
<code>nextSample</code> method provided by in
|
||||
<a href="../apidocs/org/apache/commons/math4/random/RandomUtils.DataGenerator.html">
|
||||
RandomUtils.DataGenerator</a>.
|
||||
Specifically, if <code>c</code> is a <code>java.util.Collection<T></code>
|
||||
containing at least <code>k</code> objects, and <code>randomData</code> is a
|
||||
<code>RandomUtils.DataGenerator</code> instance <code>randomData.nextSample(c, k)</code>
|
||||
will return an <code>List<T></code> instance of size <code>k</code>
|
||||
consisting of elements randomly selected from the collection.
|
||||
If <code>c</code> contains duplicate references, there may be duplicate
|
||||
references in the returned array; otherwise returned elements will be
|
||||
unique -- i.e., the sampling is without replacement among the object
|
||||
references in the collection. </p>
|
||||
<p>
|
||||
If <code>randomData</code> is a <code>RandomDataGenerator</code> instance, and
|
||||
<code>n</code> and <code>k</code> are integers with
|
||||
<code> k <= n</code>, then
|
||||
unique (i.e. the sampling is without replacement among the object
|
||||
references in the collection).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If <code>n</code> and <code>k</code> are integers with <code>k < n</code>, then
|
||||
<code>randomData.nextPermutation(n, k)</code> returns an <code>int[]</code>
|
||||
array of length <code>k</code> whose whose entries are selected randomly,
|
||||
without repetition, from the integers <code>0</code> through
|
||||
<code>n-1</code> (inclusive), i.e.,
|
||||
<code>randomData.nextPermutation(n, k)</code> returns a random
|
||||
permutation of <code>n</code> taken <code>k</code> at a time.
|
||||
</p>
|
||||
<code>n-1</code> (inclusive).
|
||||
</p>
|
||||
</subsection>
|
||||
|
||||
<subsection name="2.6 Generating data 'like' an input file" href="empirical">
|
||||
<subsection name="2.6 Generating data like an input file"
|
||||
href="empirical">
|
||||
<p>
|
||||
Using the <code>ValueServer</code> class, you can generate data based on
|
||||
the values in an input file in one of two ways:
|
||||
Using the <code>EmpiricalDistribution</code> class, you can generate data based on
|
||||
the values in an input file:
|
||||
<dl>
|
||||
<dt>Replay Mode</dt>
|
||||
<dd> The following code will read data from <code>url</code>
|
||||
(a <code>java.net.URL</code> instance), cycling through the values in the
|
||||
file in sequence, reopening and starting at the beginning again when all
|
||||
values have been read.
|
||||
<source>
|
||||
ValueServer vs = new ValueServer();
|
||||
vs.setValuesFileURL(url);
|
||||
vs.setMode(ValueServer.REPLAY_MODE);
|
||||
vs.resetReplayFile();
|
||||
double value = vs.getNext();
|
||||
// ...Generate and use more values...
|
||||
vs.closeReplayFile();
|
||||
</source>
|
||||
The values in the file are not stored in memory, so it does not matter
|
||||
how large the file is, but you do need to explicitly close the file
|
||||
as above. The expected file format is \n -delimited (i.e. one per line)
|
||||
strings representing valid floating point numbers.
|
||||
</dd>
|
||||
<dt>Digest Mode</dt>
|
||||
<dd>When used in Digest Mode, the ValueServer reads the entire input file
|
||||
and estimates a probability density function based on data from the file.
|
||||
The estimation method is essentially the
|
||||
<a href="http://nedwww.ipac.caltech.edu/level5/March02/Silverman/Silver2_6.html">
|
||||
Variable Kernel Method</a> with Gaussian smoothing. Once the density
|
||||
has been estimated, <code>getNext()</code> returns random values whose
|
||||
probability distribution matches the empirical distribution -- i.e., if
|
||||
you generate a large number of such values, their distribution should
|
||||
"look like" the distribution of the values in the input file. The values
|
||||
are not stored in memory in this case either, so there is no limit to the
|
||||
size of the input file. Here is an example:
|
||||
<source>
|
||||
ValueServer vs = new ValueServer();
|
||||
vs.setValuesFileURL(url);
|
||||
vs.setMode(ValueServer.DIGEST_MODE);
|
||||
vs.computeDistribution(500); //Read file and estimate distribution using 500 bins
|
||||
double value = vs.getNext();
|
||||
// ...Generate and use more values...
|
||||
</source>
|
||||
See the javadoc for <code>ValueServer</code> and
|
||||
<code>EmpiricalDistribution</code> for more details. Note that
|
||||
<code>computeDistribution()</code> opens and closes the input file
|
||||
by itself.
|
||||
</dd>
|
||||
<source>
|
||||
int binCount = 500;
|
||||
EmpiricalDistribution empDist = new EmpiricalDistribution(binCount);
|
||||
empDist.load("data.txt");
|
||||
RealDistribution.Sampler sampler = empDist.createSampler(RandomSource.create(RandomSource.MT));
|
||||
double value = sampler.nextDouble(); </source>
|
||||
|
||||
The entire input file is read and a probability density function is estimated
|
||||
based on data from the file.
|
||||
The estimation method is essentially the
|
||||
<a href="http://nedwww.ipac.caltech.edu/level5/March02/Silverman/Silver2_6.html">
|
||||
Variable Kernel Method</a> with Gaussian smoothing.
|
||||
The created sampler will return random values whose probability distribution
|
||||
matches the empirical distribution (i.e. if you generate a large number of
|
||||
such values, their distribution should "look like" the distribution of the
|
||||
values in the input file.
|
||||
The values are not stored in memory in this case either, so there is no limit to the
|
||||
size of the input file.
|
||||
</dl>
|
||||
</p>
|
||||
</subsection>
|
||||
|
||||
<subsection name="2.7 PRNG Pluggability" href="pluggability">
|
||||
<p>
|
||||
To enable alternative PRNGs to be "plugged in" to the commons-math data
|
||||
generation utilities and to provide a generic means to replace
|
||||
<code>java.util.Random</code> in applications, a random generator
|
||||
adaptor framework has been added to commons-math. The
|
||||
<a href="../apidocs/org/apache/commons/math4/random/RandomGenerator.html">
|
||||
RandomGenerator</a> interface abstracts the public interface of
|
||||
<code>java.util.Random</code> and any implementation of this
|
||||
interface can be used as the source of random data for the commons-math
|
||||
data generation classes. An abstract base class,
|
||||
<a href="../apidocs/org/apache/commons/math4/random/AbstractRandomGenerator.html">
|
||||
AbstractRandomGenerator</a> is provided to make implementation easier.
|
||||
This class provides default implementations of "derived" data generation
|
||||
methods based on the primitive, <code>nextDouble()</code>.
|
||||
To support generic replacement of <code>java.util.Random</code>, the
|
||||
<a href="../apidocs/org/apache/commons/math4/random/RandomAdaptor.html">
|
||||
RandomAdaptor</a> class is provided, which extends
|
||||
<code>java.util.Random</code> and wraps and delegates calls to
|
||||
a <code>RandomGenerator</code> instance.
|
||||
</p>
|
||||
|
||||
<p>Commons-math provides by itself several implementations of the <a
|
||||
href="../apidocs/org/apache/commons/math4/random/RandomGenerator.html">
|
||||
RandomGenerator</a> interface:
|
||||
<ul>
|
||||
<li><a href="../apidocs/org/apache/commons/math4/random/JDKRandomGenerator.html">JDKRandomGenerator</a>
|
||||
that extends the JDK provided generator</li>
|
||||
<li><a href="../apidocs/org/apache/commons/math4/random/AbstractRandomGenerator.html">
|
||||
AbstractRandomGenerator</a> as a helper for users generators</li>
|
||||
<li><a href="../apidocs/org/apache/commons/math4/random/BitStreamGenerator.html">
|
||||
BitStreamGenerator</a> which is an abstract class for several generators and
|
||||
which in turn is extended by:
|
||||
<ul>
|
||||
<li><a href="../apidocs/org/apache/commons/math4/random/MersenneTwister.html">MersenneTwister</a></li>
|
||||
<li><a href="../apidocs/org/apache/commons/math4/random/Well512a.html">Well512a</a></li>
|
||||
<li><a href="../apidocs/org/apache/commons/math4/random/Well1024a.html">Well1024a</a></li>
|
||||
<li><a href="../apidocs/org/apache/commons/math4/random/Well19937a.html">Well19937a</a></li>
|
||||
<li><a href="../apidocs/org/apache/commons/math4/random/Well19937c.html">Well19937c</a></li>
|
||||
<li><a href="../apidocs/org/apache/commons/math4/random/Well44497a.html">Well44497a</a></li>
|
||||
<li><a href="../apidocs/org/apache/commons/math4/random/Well44497b.html">Well44497b</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The JDK provided generator is a simple one that can be used only for very simple needs.
|
||||
The Mersenne Twister is a fast generator with very good properties well suited for
|
||||
Monte-Carlo simulation. It is equidistributed for generating vectors up to dimension 623
|
||||
and has a huge period: 2<sup>19937</sup> - 1 (which is a Mersenne prime). This generator
|
||||
is described in a paper by Makoto Matsumoto and Takuji Nishimura in 1998: <a
|
||||
href="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/ARTICLES/mt.pdf">Mersenne Twister:
|
||||
A 623-Dimensionally Equidistributed Uniform Pseudo-Random Number Generator</a>, ACM
|
||||
Transactions on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3--30.
|
||||
The WELL generators are a family of generators with period ranging from 2<sup>512</sup> - 1
|
||||
to 2<sup>44497</sup> - 1 (this last one is also a Mersenne prime) with even better properties
|
||||
than Mersenne Twister. These generators are described in a paper by François Panneton,
|
||||
Pierre L'Ecuyer and Makoto Matsumoto <a
|
||||
href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng.pdf">Improved Long-Period
|
||||
Generators Based on Linear Recurrences Modulo 2</a> ACM Transactions on Mathematical Software,
|
||||
32, 1 (2006). The errata for the paper are in <a
|
||||
href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng-errata.txt">wellrng-errata.txt</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
For simple sampling, any of these generators is sufficient. For Monte-Carlo simulations the
|
||||
JDK generator does not have any of the good mathematical properties of the other generators,
|
||||
so it should be avoided. The Mersenne twister and WELL generators have equidistribution properties
|
||||
proven according to their bits pool size which is directly linked to their period (all of them
|
||||
have maximal period, i.e. a generator with size n pool has a period 2<sup>n</sup>-1). They also
|
||||
have equidistribution properties for 32 bits blocks up to s/32 dimension where s is their pool size.
|
||||
So WELL19937c for exemple is equidistributed up to dimension 623 (19937/32). This means a Monte-Carlo
|
||||
simulation generating a vector of n variables at each iteration has some guarantees on the properties
|
||||
of the vector as long as its dimension does not exceed the limit. However, since we use bits from two
|
||||
successive 32 bits generated integers to create one double, this limit is smaller when the variables are
|
||||
of type double. so for Monte-Carlo simulation where less the 16 doubles are generated at each round,
|
||||
WELL1024 may be sufficient. If a larger number of doubles are needed a generator with a larger pool
|
||||
would be useful.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The WELL generators are more modern then MersenneTwister (the paper describing than has been published
|
||||
in 2006 instead of 1998) and fix some of its (few) drawbacks. If initialization array contains many
|
||||
zero bits, MersenneTwister may take a very long time (several hundreds of thousands of iterations to
|
||||
reach a steady state with a balanced number of zero and one in its bits pool). So the WELL generators
|
||||
are better to <i>escape zeroland</i> as explained by the WELL generators creators. The Well19937a and
|
||||
Well44497a generator are not maximally equidistributed (i.e. there are some dimensions or bits blocks
|
||||
size for which they are not equidistributed). The Well512a, Well1024a, Well19937c and Well44497b are
|
||||
maximally equidistributed for blocks size up to 32 bits (they should behave correctly also for double
|
||||
based on more than 32 bits blocks, but equidistribution is not proven at these blocks sizes).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The MersenneTwister generator uses a 624 elements integer array, so it consumes less than 2.5 kilobytes.
|
||||
The WELL generators use 6 integer arrays with a size equal to the pool size, so for example the
|
||||
WELL44497b generator uses about 33 kilobytes. This may be important if a very large number of
|
||||
generator instances were used at the same time.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
All generators are quite fast. As an example, here are some comparisons, obtained on a 64 bits JVM on a
|
||||
linux computer with a 2008 processor (AMD phenom Quad 9550 at 2.2 GHz). The generation rate for
|
||||
MersenneTwister was between 25 and 27 millions doubles per second (remember we generate two 32 bits integers for
|
||||
each double). Generation rates for other PRNG, relative to MersenneTwister:
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<table border="1" align="center">
|
||||
<tr BGCOLOR="#CCCCFF"><td colspan="2"><font size="+1">Example of performances</font></td></tr>
|
||||
<tr BGCOLOR="#EEEEFF"><font size="+1"><td>Name</td><td>generation rate (relative to MersenneTwister)</td></font></tr>
|
||||
<tr><td><a href="../apidocs/org/apache/commons/math4/random/MersenneTwister.html">MersenneTwister</a></td><td>1</td></tr>
|
||||
<tr><td><a href="../apidocs/org/apache/commons/math4/random/JDKRandomGenerator.html">JDKRandomGenerator</a></td><td>between 0.96 and 1.16</td></tr>
|
||||
<tr><td><a href="../apidocs/org/apache/commons/math4/random/Well512a.html">Well512a</a></td><td>between 0.85 and 0.88</td></tr>
|
||||
<tr><td><a href="../apidocs/org/apache/commons/math4/random/Well1024a.html">Well1024a</a></td><td>between 0.63 and 0.73</td></tr>
|
||||
<tr><td><a href="../apidocs/org/apache/commons/math4/random/Well19937a.html">Well19937a</a></td><td>between 0.70 and 0.71</td></tr>
|
||||
<tr><td><a href="../apidocs/org/apache/commons/math4/random/Well19937c.html">Well19937c</a></td><td>between 0.57 and 0.71</td></tr>
|
||||
<tr><td><a href="../apidocs/org/apache/commons/math4/random/Well44497a.html">Well44497a</a></td><td>between 0.69 and 0.71</td></tr>
|
||||
<tr><td><a href="../apidocs/org/apache/commons/math4/random/Well44497b.html">Well44497b</a></td><td>between 0.65 and 0.71</td></tr>
|
||||
</table>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
So for most simulation problems, the better generators like <a
|
||||
href="../apidocs/org/apache/commons/math4/random/Well19937c.html">Well19937c</a> and <a
|
||||
href="../apidocs/org/apache/commons/math4/random/Well44497b.html">Well44497b</a> are probably very good choices.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Note that <em>none</em> of these generators are suitable for cryptography. They are devoted
|
||||
to simulation, and to generate very long series with strong properties on the series as a whole
|
||||
(equidistribution, no correlation ...). They do not attempt to create small series but with
|
||||
very strong properties of unpredictability as needed in cryptography.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Examples:
|
||||
<dl>
|
||||
<dt>Create a RandomGenerator based on RngPack's Mersenne Twister</dt>
|
||||
<dd>To create a RandomGenerator using the RngPack Mersenne Twister PRNG
|
||||
as the source of randomness, extend <code>AbstractRandomGenerator</code>
|
||||
overriding the derived methods that the RngPack implementation provides:
|
||||
<source>
|
||||
import edu.cornell.lassp.houle.RngPack.RanMT;
|
||||
/**
|
||||
* AbstractRandomGenerator based on RngPack RanMT generator.
|
||||
*/
|
||||
public class RngPackGenerator extends AbstractRandomGenerator {
|
||||
|
||||
private RanMT random = new RanMT();
|
||||
|
||||
public void setSeed(long seed) {
|
||||
random = new RanMT(seed);
|
||||
}
|
||||
|
||||
public double nextDouble() {
|
||||
return random.raw();
|
||||
}
|
||||
|
||||
public double nextGaussian() {
|
||||
return random.gaussian();
|
||||
}
|
||||
|
||||
public int nextInt(int n) {
|
||||
return random.choose(n);
|
||||
}
|
||||
|
||||
public boolean nextBoolean() {
|
||||
return random.coin();
|
||||
}
|
||||
}
|
||||
</source>
|
||||
</dd>
|
||||
<dt>Use the Mersenne Twister RandomGenerator in place of
|
||||
<code>java.util.Random</code> in <code>RandomData</code></dt>
|
||||
<dd>
|
||||
<source>
|
||||
RandomData randomData = new RandomDataImpl(new RngPackGenerator());
|
||||
</source>
|
||||
</dd>
|
||||
<dt>Create an adaptor instance based on the Mersenne Twister generator
|
||||
that can be used in place of a <code>Random</code></dt>
|
||||
<dd>
|
||||
<source>
|
||||
RandomGenerator generator = new RngPackGenerator();
|
||||
Random random = RandomAdaptor.createAdaptor(generator);
|
||||
// random can now be used in place of a Random instance, data generation
|
||||
// calls will be delegated to the wrapped Mersenne Twister
|
||||
</source>
|
||||
</dd>
|
||||
</dl>
|
||||
</p>
|
||||
</subsection>
|
||||
|
||||
</section>
|
||||
|
||||
</body>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
package org.apache.commons.math4.distribution;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
|
@ -28,11 +28,6 @@ import org.apache.commons.math4.TestUtils;
|
|||
import org.apache.commons.math4.analysis.UnivariateFunction;
|
||||
import org.apache.commons.math4.analysis.integration.BaseAbstractUnivariateIntegrator;
|
||||
import org.apache.commons.math4.analysis.integration.IterativeLegendreGaussIntegrator;
|
||||
import org.apache.commons.math4.distribution.ConstantRealDistribution;
|
||||
import org.apache.commons.math4.distribution.NormalDistribution;
|
||||
import org.apache.commons.math4.distribution.RealDistribution;
|
||||
import org.apache.commons.math4.distribution.RealDistributionAbstractTest;
|
||||
import org.apache.commons.math4.distribution.UniformRealDistribution;
|
||||
import org.apache.commons.math4.exception.MathIllegalStateException;
|
||||
import org.apache.commons.math4.exception.NullArgumentException;
|
||||
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
||||
|
@ -44,7 +39,7 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test cases for the EmpiricalDistribution class
|
||||
* Test cases for the {@link EmpiricalDistribution} class.
|
||||
*/
|
||||
public final class EmpiricalDistributionTest extends RealDistributionAbstractTest {
|
||||
|
||||
|
@ -257,39 +252,6 @@ public final class EmpiricalDistributionTest extends RealDistributionAbstractTes
|
|||
TestUtils.assertEquals(expectedGeneratorUpperBounds, dist.getGeneratorUpperBounds(), tol);
|
||||
}
|
||||
|
||||
// XXX REMOVE (test "embedded RNG" which is to be removed)
|
||||
// @Test
|
||||
// public void testGeneratorConfig() {
|
||||
// double[] testData = {0, 1, 2, 3, 4};
|
||||
// RandomGenerator generator = new RandomAdaptorTest.ConstantGenerator(0.5);
|
||||
|
||||
// EmpiricalDistribution dist = new EmpiricalDistribution(5, generator);
|
||||
// dist.load(testData);
|
||||
// for (int i = 0; i < 5; i++) {
|
||||
// Assert.assertEquals(2.0, dist.getNextValue(), 0d);
|
||||
// }
|
||||
|
||||
// // Verify no NPE with null generator argument
|
||||
// dist = new EmpiricalDistribution(5, (RandomGenerator) null);
|
||||
// dist.load(testData);
|
||||
// dist.getNextValue();
|
||||
// }
|
||||
|
||||
// XXX REMOVE (test "embedded RNG" which is to be removed)
|
||||
// @Test
|
||||
// public void testReSeed() throws Exception {
|
||||
// empiricalDistribution.load(url);
|
||||
// empiricalDistribution.reSeed(100);
|
||||
// final double [] values = new double[10];
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// values[i] = empiricalDistribution.getNextValue();
|
||||
// }
|
||||
// empiricalDistribution.reSeed(100);
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// Assert.assertEquals(values[i],empiricalDistribution.getNextValue(), 0d);
|
||||
// }
|
||||
// }
|
||||
|
||||
private void verifySame(EmpiricalDistribution d1, EmpiricalDistribution d2) {
|
||||
Assert.assertEquals(d1.isLoaded(), d2.isLoaded());
|
||||
Assert.assertEquals(d1.getBinCount(), d2.getBinCount());
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
|
||||
/**
|
||||
* Test cases for the AbstractRandomGenerator class.
|
||||
*
|
||||
*/
|
||||
|
||||
public class AbstractRandomGeneratorTest extends RandomGeneratorAbstractTest {
|
||||
|
||||
public AbstractRandomGeneratorTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RandomGenerator makeGenerator() {
|
||||
RandomGenerator generator = new TestRandomGenerator();
|
||||
generator.setSeed(1001);
|
||||
return generator;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.commons.math4.random.BitsStreamGenerator;
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
|
||||
/**
|
||||
* Test cases for the BitStreamGenerator class
|
||||
*
|
||||
*/
|
||||
|
||||
public class BitsStreamGeneratorTest extends RandomGeneratorAbstractTest {
|
||||
|
||||
public BitsStreamGeneratorTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RandomGenerator makeGenerator() {
|
||||
RandomGenerator generator = new TestBitStreamGenerator();
|
||||
generator.setSeed(1000);
|
||||
return generator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test BitStreamGenerator using a Random as bit source.
|
||||
*/
|
||||
static class TestBitStreamGenerator extends BitsStreamGenerator {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private BitRandom ran = new BitRandom();
|
||||
|
||||
@Override
|
||||
public void setSeed(int seed) {
|
||||
ran.setSeed(seed);
|
||||
clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSeed(int[] seed) {
|
||||
ran.setSeed(seed[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSeed(long seed) {
|
||||
ran.setSeed((int) seed);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int next(int bits) {
|
||||
return ran.nextBits(bits);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend Random to expose next(bits)
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
static class BitRandom extends Random {
|
||||
public BitRandom() {
|
||||
super();
|
||||
}
|
||||
public int nextBits(int bits) {
|
||||
return next(bits);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,395 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import org.apache.commons.math4.random.ISAACRandom;
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public final class ISAACTest extends RandomGeneratorAbstractTest {
|
||||
|
||||
@Override
|
||||
protected RandomGenerator makeGenerator() {
|
||||
return new ISAACRandom(500);
|
||||
}
|
||||
|
||||
private static final int[] SEED_1 = {
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
|
||||
};
|
||||
|
||||
private static final int[] SEED_2 = {
|
||||
0x61b12894, 0x4a43da95, 0x03e4d8c5, 0xd92e174f, 0xe8998d71, 0x0ecaaa89, 0xaba8a61d, 0xcfd457fc,
|
||||
0xbf25f0a7, 0xe05b20a9, 0xdc744513, 0x9a3eb193, 0x1b69542b, 0xedb0890d, 0xca6b233d, 0xfcabf357,
|
||||
0x297e95f0, 0x1a6c456f, 0x0e3738b0, 0x1c0517f2, 0xcfd105bd, 0x3b7c39eb, 0x141804e9, 0x8a13a0d1,
|
||||
0x3e57cf5c, 0x35471206, 0x00115ef6, 0x3424ec23, 0x2a6a63a7, 0x4cecb3e8, 0xecb4d341, 0x63d25ac1,
|
||||
0x8b68eafd, 0x0eca65b4, 0xd8354668, 0xb37b1ff8, 0x82e80ce3, 0x4c212f9c, 0x58d82d5f, 0x47f36348,
|
||||
0x5bd88987, 0xf77ac66e, 0x75ff93ee, 0xef763453, 0x9705f8b6, 0x64e44649, 0x84f03338, 0x902120e9,
|
||||
0x5350212e, 0x34f466f8, 0x97f96d0e, 0x7f1db8f0, 0x15879833, 0xefee14b4, 0xda25520a, 0x81c0dd7c,
|
||||
0xa20bb729, 0x2fd76844, 0x1b522548, 0xf394565d, 0xabff5f1b, 0x38eaf2e7, 0x364a6ccf, 0x8ed5e169,
|
||||
0xe76aae18, 0x0e4c0b62, 0x68356792, 0x8bc4aa83, 0x31546e69, 0xa6d04441, 0x2abef1df, 0xa40a164e,
|
||||
0x8a8d00ba, 0x32b38dba, 0x6f66a7c6, 0x493b0c84, 0xd86846f0, 0x50d50178, 0x26a7e67c, 0x97802153,
|
||||
0xf35f4ad3, 0x4b54b54e, 0x35bcaef1, 0xc3ed09d6, 0xc127bc55, 0xb2e34ea4, 0x8d674133, 0xed82f03d,
|
||||
0xa8443b28, 0x30bf4bd9, 0x6748419c, 0x155eb313, 0xb17c85da, 0xcd0d8014, 0xf1e95740, 0x5e769ed2,
|
||||
0xf8fa5819, 0x3bd0d93a, 0xa46eaf3f, 0x90f5ae2c, 0x912aa83d, 0x66995d3d, 0x8359b2a9, 0x64534b93,
|
||||
0x1fa38094, 0x89fde50c, 0xef925ef5, 0x4edf2287, 0xc6e82b2b, 0x99812c32, 0x53f6fe01, 0xf104263f,
|
||||
0xbc5d8b8e, 0x6f23f102, 0xb6cc174d, 0xb47b2421, 0xdb083f26, 0xd67a1f25, 0x4f4b0c50, 0x86fca924,
|
||||
0x442036ba, 0x0d7dba08, 0xf6d89c1e, 0x65c9e28e, 0xd689fafc, 0x47f7ae9b, 0x3cb86674, 0x798dc4ce,
|
||||
0x62a2d235, 0x73912420, 0x276ef9b4, 0x50deb689, 0x40b6b744, 0x84d79856, 0x86e5f0c6, 0x835a552b,
|
||||
0xeb73ff95, 0xe428e392, 0x1d60bf15, 0x9ad09e35, 0x783e60ae, 0xb42feb61, 0x028a0343, 0x90febcfc,
|
||||
0xdffb01c8, 0x1087ab1e, 0x84d8a8f9, 0xe5433763, 0x897548cc, 0xb4075ece, 0xd0a5a727, 0x0a84da19,
|
||||
0x0f33964b, 0x5634a097, 0xb7cbac77, 0xe50340eb, 0x93f0ce63, 0x0c743ed4, 0xf6f6f015, 0x30f74cca,
|
||||
0xbb0306a7, 0x3d037943, 0x22f2979e, 0x3591b2c3, 0x9a772e24, 0x5c5812fa, 0x9e733c8a, 0xaae1c943,
|
||||
0xd0b7d924, 0x56b9c463, 0xfaedb557, 0x139b7aa5, 0xe173f123, 0x2d0686a2, 0x03cd0bef, 0x4f47c01e,
|
||||
0x4cf9fb83, 0xba9d433e, 0x95a620d5, 0x62b67429, 0xe836067d, 0x606bc5f7, 0x36af81e2, 0xae0b8b30,
|
||||
0x38ffe5fa, 0xb548228b, 0xc2a25bcb, 0x4ba139ee, 0xab214ad7, 0x66ef4f50, 0x5f8787fa, 0xcb5982b1,
|
||||
0xdbb48ff8, 0x14eaa914, 0xe0874168, 0x3e578246, 0x488c1c11, 0x982039a2, 0xde096b35, 0xa420fb41,
|
||||
0x197a1b67, 0x16eabc59, 0x0e689585, 0x24db72b7, 0xf89878c3, 0x04a5e854, 0x3346da02, 0xb4bb6a04,
|
||||
0x278a0dd4, 0x7bb6e224, 0x92e219c3, 0x595f8a33, 0xedd87ae6, 0xa313cc9f, 0x385c1d3a, 0x0a8b1db5,
|
||||
0xb192379d, 0x3a0be0eb, 0xb8ba269b, 0x1f0c62a5, 0x56307342, 0x8fc9ac94, 0xec91a232, 0xa7b8d3db,
|
||||
0xfbf43a60, 0xa773463e, 0x72d5a4d1, 0x8ddf1755, 0x27da39bb, 0xa8d4668a, 0xd2f3bbfc, 0xa188d6af,
|
||||
0x82ed668e, 0xb45f0032, 0xcdfd4ca0, 0x14e5a80d, 0x456594bc, 0x68efcdd5, 0x7dbf1f9d, 0x74599699,
|
||||
0xfc8639e8, 0x4139e791, 0x9c06921a, 0xc5121d36, 0xd15b9425, 0x0670dca7, 0xbc60c353, 0xaa49e487,
|
||||
0xa7cb5854, 0xd06ddbdb, 0xcb4be0d2, 0x8391ab98, 0xc750d7bf, 0x365340b1, 0x264677c7, 0xb76075a4
|
||||
};
|
||||
|
||||
/**
|
||||
* The output sequence generated by reference ISAAC algorithm in C language.
|
||||
* For initial seeding is used SEED_1 data array.
|
||||
* 1024 signed 32-bit integers in hexadecimal representation.
|
||||
*/
|
||||
private static final int[] EXPECTED_SEQUENCE_1 = {
|
||||
0x182600f3, 0x300b4a8d, 0x301b6622, 0xb08acd21, 0x296fd679, 0x995206e9, 0xb3ffa8b5, 0x0fc99c24,
|
||||
0x5f071faf, 0x52251def, 0x894f41c2, 0xcc4c9afb, 0x96c33f74, 0x347cb71d, 0xc90f8fbd, 0xa658f57a,
|
||||
0xc5c29e18, 0x6249fa29, 0xbae16ffa, 0x25c871bd, 0xf4c75e24, 0x5ab3eab9, 0xac450b8f, 0x1629cfa4,
|
||||
0x0016e86f, 0xf27c4d0d, 0x67648b17, 0x05c04fce, 0x44d3ff79, 0xc6acd20f, 0x472fd994, 0x842131c4,
|
||||
0xead4a900, 0xc01eda0d, 0x9e604c7b, 0xfb8a0e99, 0x02e17b6f, 0xe8b4f627, 0xc7041eae, 0x42d19cd7,
|
||||
0xa358eb94, 0x19ca2158, 0x6be6ce81, 0x4b90a4de, 0x26f0774d, 0x4e83930a, 0x2492d476, 0xb97ffabe,
|
||||
0x675cc8ae, 0x4cfdd254, 0x5d3c00ea, 0x7bba5ead, 0x6f461810, 0xbef63eea, 0x72eb767b, 0xed6e963b,
|
||||
0xb026016d, 0x17cb7ebf, 0xa7dc6e56, 0xf460bdf1, 0x1ffe0e04, 0x902b347d, 0x02c0d8ab, 0x98cb3f8b,
|
||||
0x6f359a39, 0x9521825f, 0x9026d97e, 0xde342516, 0x890a740c, 0x0f2969e4, 0x2e7ea9ed, 0x394b8a4f,
|
||||
0x1bdf1fd0, 0x15d565b4, 0xbaf0406d, 0x4dac20db, 0x03359832, 0xe34802d5, 0xcc5fff02, 0x0935ad6e,
|
||||
0x7c53c9b2, 0xb10b5d29, 0x4fbb94be, 0xd7e48546, 0xb7cfa23c, 0x7f081c9a, 0xe099baf1, 0x9c7dc323,
|
||||
0xb831ad14, 0x5b563101, 0xfa55319b, 0x060ded54, 0xc5418124, 0x765f0dba, 0x1ad3d9d5, 0x3f07ec49,
|
||||
0xdd5e06c6, 0xc230e2ac, 0xc6ba1971, 0x9cc17bcc, 0x10b22a22, 0x7dfc8c7f, 0xb3310333, 0x205530ee,
|
||||
0xdbf38a8f, 0x003a02f5, 0x007e96a3, 0x36658201, 0x08dfd64f, 0x6275acf3, 0x3d29669b, 0x6b2f4538,
|
||||
0xb0cc336b, 0x1d3043eb, 0x1ad1d764, 0x4c655b84, 0x7a725bb2, 0xb3fc5c66, 0x80b4b915, 0xb2cbd9e4,
|
||||
0x2992dfc6, 0xdf8be548, 0xb310d06e, 0x436385c6, 0x44d6e893, 0x44c4d79d, 0xe3bb2064, 0xe41ea465,
|
||||
0x3ff4cc70, 0x9d21ac42, 0x672c3725, 0xa43a1d02, 0xfd84b19b, 0x5b6fb132, 0x4af40896, 0xe15000a6,
|
||||
0x7cab12f6, 0x8b8e753c, 0xfb253454, 0x359ac366, 0x67822b45, 0x290a1140, 0xade6e428, 0x6095efcb,
|
||||
0x99d8d9e6, 0xa5b5981d, 0x332c95d6, 0xaf5cfcab, 0x161f5ca6, 0x1844cee2, 0xffb8ab5c, 0x82fccaeb,
|
||||
0x49ecf97a, 0x7a60fabd, 0xf9585a3a, 0x4eb6bd32, 0x3b347002, 0xf4930dba, 0x5d21d51e, 0x64e8e3f4,
|
||||
0x52801fa8, 0x71ce907c, 0x872783a4, 0x0761dc80, 0x5c509848, 0x41ba2adc, 0x7e2f5520, 0x85c5eec2,
|
||||
0x368d3d00, 0x5fc7c5f3, 0xb849d785, 0xd95f25b3, 0x79801fd5, 0xbf2443d6, 0x360d41cd, 0x651b11c0,
|
||||
0x801a89ca, 0x8b9e6b94, 0xfde283c4, 0xcc5e6974, 0x2b2f4c09, 0x8b2160a8, 0xdbf57f01, 0x76aa1c4e,
|
||||
0x11f0831a, 0x54713d17, 0xc99a2639, 0x4c373e7a, 0x09e6e57f, 0x71f63b07, 0x7be3f02e, 0x2c907ade,
|
||||
0xe5f489f6, 0x0b0cd6da, 0xb566e14c, 0x0f955969, 0xa0e5710b, 0x80d8c2de, 0x9971e496, 0xc7efbc2f,
|
||||
0x97a48e53, 0x2d845c0d, 0xe1194b0e, 0xad2ba480, 0xd5253552, 0xca890b31, 0x60060afb, 0x89dae927,
|
||||
0x565e2229, 0x43abc21c, 0x03dd14a5, 0xbbadd184, 0x9e979702, 0x2f659883, 0xf313adec, 0x621bd7ca,
|
||||
0xb6470834, 0x4c3901c6, 0x32028bb8, 0x9ded8244, 0x66907654, 0x0a06b272, 0x4a8ec630, 0x4207d36f,
|
||||
0x3e7a8b49, 0x13871be7, 0xbf7af48e, 0x3de0df39, 0x0e864542, 0x8c090a23, 0xaf90e49e, 0x97661c5e,
|
||||
0x365aa66c, 0x0073e342, 0x9c8ac447, 0x6f57e7ce, 0xd5be7ffa, 0x89651d84, 0x53f78eaa, 0x8173dc04,
|
||||
0xd70b1e10, 0x43c1a57b, 0x10c8a5ab, 0xed6abd62, 0x2f840e43, 0x4873d91e, 0x49f413fc, 0x5d89a1c1,
|
||||
0xd3a388fc, 0x96c59cf4, 0x456f1edd, 0x3dd20023, 0xa264e933, 0xd32956e5, 0xd91aa738, 0xe76dd339,
|
||||
0x7a68710f, 0x6554abda, 0x90c10757, 0x0b5e435f, 0xaf7d1fb8, 0x01913fd3, 0x6a158d10, 0xb8f6fd4a,
|
||||
0xc2b9aa36, 0x96da2655, 0xfe1e42d5, 0x56e6cd21, 0xd5b2d750, 0x7229ea81, 0x5de87abb, 0xb6b9d766,
|
||||
0x1e16614c, 0x3b708f99, 0x5cf824cd, 0xa4ca0cf1, 0x62d31911, 0x7cdd662f, 0xcb9e1563, 0x79ae4c10,
|
||||
0x080c79ec, 0x18080c8e, 0x4a0a283c, 0x3dde9f39, 0x09c36f90, 0xad567643, 0x08294766, 0xb4415f7d,
|
||||
0x5597ec0f, 0x78ffa568, 0x8bace62e, 0x4188bfcd, 0xc87c8006, 0xafa92a6d, 0x50fc8194, 0xcae8deba,
|
||||
0x33f6d7b1, 0x53245b79, 0x61119a5a, 0x7e315aeb, 0xe75b41c9, 0xd2a93b51, 0xec46b0b6, 0x1ed3ff4e,
|
||||
0x5d023e65, 0xadf6bc23, 0xf7f58f7b, 0xe4f3a26a, 0x0c571a7d, 0xed35e5ee, 0xeadebeac, 0x30bcc764,
|
||||
0x66f1e0ab, 0x826dfa89, 0x0d9c7e7e, 0xe7e26581, 0xd5990dfb, 0x02c9b944, 0x4112d96c, 0x3ff1e524,
|
||||
0xc35e4580, 0xfdfef62d, 0xb83f957a, 0xbfc7f7cc, 0xb510ce0e, 0xcd7411a7, 0x04db4e13, 0x76904b6d,
|
||||
0x08607f04, 0x3718d597, 0x46c0a6f5, 0x8406b137, 0x309bfb78, 0xf7d3f39f, 0x8c2f0d55, 0xc613f157,
|
||||
0x127dd430, 0x72c9137d, 0x68a39358, 0x07c28cd1, 0x848f520a, 0xdd2dc1d5, 0x9388b13b, 0x28e7cb78,
|
||||
0x03fb88f4, 0xb0b84e7b, 0x14c8009b, 0x884d6825, 0x21c171ec, 0x0809e494, 0x6a107589, 0x12595a19,
|
||||
0x0bb3263f, 0x4d8fae82, 0x2a98121a, 0xb00960ba, 0x6708a2bc, 0x35a124b5, 0xbccaaeed, 0x294d37e5,
|
||||
0xd405ded8, 0x9f39e2d9, 0x21835c4d, 0xe89b1a3b, 0x7364944b, 0xbd2e5024, 0x6a123f57, 0x34105a8c,
|
||||
0x5ad0d3b0, 0xcc033ce3, 0xd51f093d, 0x56a001e3, 0x01a9bd70, 0x8891b3db, 0x13add922, 0x3d77d9a2,
|
||||
0x0e7e0e67, 0xd73f72d4, 0x917bdec2, 0xa37f63ff, 0x23d74f4e, 0x3a6ce389, 0x0606cf9f, 0xde11ed34,
|
||||
0x70cc94ae, 0xcb0eee4a, 0x13edc0cb, 0xfe29661c, 0xdb6dbe96, 0xb388d96c, 0x33bc405d, 0xa6d12101,
|
||||
0x2f36fa86, 0x7ded386f, 0xe6344451, 0xcd57c7f7, 0x1b0dcdc1, 0xcd49ebdb, 0x9e8a51da, 0x12a0594b,
|
||||
0x60d4d5f8, 0x91c8d925, 0xe43d0fbb, 0x5d2a542f, 0x451e7ec8, 0x2b36505c, 0x37c0ed05, 0x2364a1aa,
|
||||
0x814bc24c, 0xe3a662d9, 0xf2b5cc05, 0xb8b0ccfc, 0xb058bafb, 0x3aea3dec, 0x0d028684, 0x64af0fef,
|
||||
0x210f3925, 0xb67ec13a, 0x97166d14, 0xf7e1cdd0, 0x5adb60e7, 0xd5295ebc, 0x28833522, 0x60eda8da,
|
||||
0x7bc76811, 0xac9fe69d, 0x30ab93ec, 0x03696614, 0x15e3a5b9, 0xecc5dc91, 0x1d3b8e97, 0x7275e277,
|
||||
0x538e1f4e, 0x6cb167db, 0xa7a2f402, 0x2db35dfe, 0xa8bcc22d, 0xd8c58a6a, 0x6a529b0b, 0x0fd43963,
|
||||
0xafc17a97, 0x943c3c74, 0x95138769, 0x6f4e0772, 0xb143b688, 0x3b18e752, 0x69d2e4ae, 0x8107c9ff,
|
||||
0xcdbc62e2, 0x5781414f, 0x8b87437e, 0xa70e1101, 0x91dabc65, 0x4e232cd0, 0x229749b5, 0xd7386806,
|
||||
0xb3c3f24b, 0x60dc5207, 0x0bdb9c30, 0x1a70e7e9, 0xf37c71d5, 0x44b89b08, 0xb4d2f976, 0xb40e27bc,
|
||||
0xffdf8a80, 0x9c411a2a, 0xd0f7b37d, 0xef53cec4, 0xeca4d58a, 0x0b923200, 0xcf22e064, 0x8ebfa303,
|
||||
0xf7cf814c, 0x32ae2a2b, 0xb5e13dae, 0xc998f9ff, 0x349947b0, 0x29cf72ce, 0x17e38f85, 0xf3b26129,
|
||||
0xd45d6d81, 0x09b3ce98, 0x860536b8, 0xe5792e1b, 0x12ad6419, 0xf5f71c69, 0xcbc8b7c2, 0x8f651659,
|
||||
0xa0cc74f3, 0xd78cb99e, 0x51c08d83, 0x29f55449, 0x002ed713, 0x38a824f3, 0x57161df6, 0x7452e319,
|
||||
0x25890e2e, 0xc7442433, 0x4a5f6355, 0x6a83e1e0, 0x823cedb6, 0xf1d444eb, 0x88381097, 0x5de3743e,
|
||||
0x46ca4f9a, 0xd8370487, 0xedec154a, 0x433f1afb, 0xf5fad54f, 0x98db2fb4, 0xe448e96d, 0xf650e4c8,
|
||||
0x4bb5af29, 0x9d855e89, 0xc54cd95b, 0x46d95ca5, 0xef73fbf0, 0xf943f672, 0x86ba527f, 0x9d8d1908,
|
||||
0xf3310c92, 0x05340e15, 0x07cffad9, 0x21e2547e, 0x8c17eff0, 0xd32be060, 0x8aba3ffb, 0x94d40125,
|
||||
0xc5a87748, 0x824c2009, 0x73c0e762, 0xcdfec2af, 0x0e6c51b3, 0xa86f875e, 0xbc6172c7, 0xf7f395f1,
|
||||
0x3f7579b3, 0x7aa114ed, 0x165b1015, 0xd531161a, 0xe36ef5bb, 0xdc153e5f, 0x1d0cb81b, 0xceffc147,
|
||||
0x6079e4ce, 0xc3142d8f, 0xa617a083, 0xb54fed6f, 0xc3c7be2c, 0x02614abf, 0x6fb5ce56, 0xd21e796c,
|
||||
0x2d0985de, 0xe9f84163, 0xc1a71e3c, 0x2887d96f, 0x57c4c925, 0x05efe294, 0x88157153, 0x9a30c4e8,
|
||||
0x8854a0a1, 0x02503f7d, 0x0cd6ef81, 0x1da4f25a, 0xe8fa3860, 0x32e39273, 0x4c8652d6, 0x9ab3a42f,
|
||||
0x9ead7f70, 0x836d8003, 0x6cbe7935, 0x721502dd, 0x5a48755c, 0x07497cae, 0xde462f4d, 0x92f57ea7,
|
||||
0x1fe26ce0, 0x27c82282, 0xd6ec2f2b, 0x80c6e402, 0xce86fdfc, 0x52649d6c, 0xc798f047, 0x45bae606,
|
||||
0x891aec49, 0x66c97340, 0x9ca45e1c, 0x4286619c, 0xf5f9cc3b, 0x4e823ad3, 0xc0d5d42a, 0xaee19096,
|
||||
0x3d469303, 0xfe4cb380, 0xc9cd808c, 0x37a97df6, 0x308f751f, 0x276df0b4, 0xe5fbb9c7, 0x97ca2070,
|
||||
0x88412761, 0x2ce5d3d5, 0xd7b43abe, 0xa30519ad, 0x26414ff3, 0xc5bde908, 0x275ead3a, 0x26ceb003,
|
||||
0xbf1bd691, 0x037464c0, 0xe24124c0, 0x81d4cc5f, 0x484525e4, 0x1c3a4524, 0x9e7e4f04, 0xe1279bff,
|
||||
0x6dd1943a, 0x403dae08, 0x82846526, 0xd5683858, 0x29322d0d, 0xa949bea2, 0x74096ae7, 0x85a13f85,
|
||||
0x68235b9d, 0x8ef4bce6, 0x142a6e85, 0xdad1b22a, 0xb7546681, 0x959e234e, 0xfd8650d8, 0x3e730fa8,
|
||||
0x56f55a71, 0xd20adf03, 0x7cdc78a2, 0x19047c79, 0x253b1d7a, 0x4389a84a, 0x0aeb8165, 0x9c15db3b,
|
||||
0xaafef5a7, 0xbe8b06b2, 0xb5fe87c0, 0xe2a4ef71, 0xd9d711f9, 0xecfcf20b, 0x80fac4c2, 0xbbb8abc4,
|
||||
0x239e3b0a, 0x858129a6, 0xd97cd348, 0x8a30738a, 0xc5b71937, 0xd649a428, 0x18c1ef9a, 0x75c08a36,
|
||||
0xc921f94e, 0xdf9afa29, 0x040f7074, 0x72f5972f, 0x84ef01da, 0x2cb7b77f, 0x867027d7, 0x9ce0199d,
|
||||
0x71865c4c, 0x7a36af93, 0x6c48ddd8, 0x19b48fd0, 0x75f4e9e2, 0x0084cfe5, 0x63bfd4d8, 0x9783cdee,
|
||||
0x64f2632c, 0xf1b20eaf, 0xcc8bfa2d, 0x39ddf25a, 0x740e0066, 0x9ddb477f, 0x12b2cfb6, 0xd067fce5,
|
||||
0x1a4b6a53, 0x001cdb95, 0x12c06908, 0x531ac6bf, 0x513c1764, 0xf7476978, 0x1be79937, 0x8a8dfaa3,
|
||||
0x70a1660e, 0xfb737b1a, 0x3f28ee63, 0xc1a51375, 0x84bd6dd6, 0xe4a51d21, 0xeafed133, 0x22ae0582,
|
||||
0x4d678f26, 0xf854b522, 0x31907d62, 0x4b55dd99, 0x04d3658a, 0x19c1e69c, 0xc6112fdd, 0xc66699fd,
|
||||
0xa0eabe6b, 0x3724d4dc, 0x0d28fe52, 0x46819e2e, 0x96f703ac, 0x21182ca3, 0x2e7b022f, 0x31860f13,
|
||||
0x1956b1e5, 0xe1322228, 0x08063a85, 0x1d964589, 0x94d90481, 0x53c078f3, 0x5afb43ae, 0x1e3437f7,
|
||||
0x877eb7b4, 0x5d67133c, 0xa385cb2c, 0xb82f2703, 0xef05ee06, 0x931dd7e2, 0x10d210aa, 0xe21339cc,
|
||||
0x479c3a22, 0x613b67b2, 0x33c5321c, 0xa5f48ac4, 0xba5590c8, 0xeb244925, 0xd0ef3cc9, 0xd8c423fb,
|
||||
0x15cfcc5c, 0x1feb2e4f, 0x36ec0ea3, 0xdbef7d9f, 0xd5ec6bf4, 0x3d3dff8a, 0x1e04a7f7, 0x8766bb54,
|
||||
0x9a1d7745, 0xc79a1749, 0xb8d2486d, 0x582e3014, 0xa82427f5, 0x65dfa427, 0xbc5654c1, 0xbd086f26,
|
||||
0x0451516d, 0xff4cfc35, 0x81f2864d, 0x31860f05, 0xd0638e1a, 0xb059261d, 0x3d1e9150, 0x21e2a51c,
|
||||
0x82d53d12, 0x1010b275, 0x786b2908, 0x4d3cfbda, 0x94a302f4, 0x95c85eaa, 0xd7e1c7be, 0x82ac484f,
|
||||
0xd24daa9a, 0x70055204, 0xbf27ef0d, 0x740ebb34, 0x47a1ff2f, 0x037e5e95, 0x3362d8d3, 0xb08c9e58,
|
||||
0x7036b9a5, 0x3354197a, 0x326c9f12, 0xab99166e, 0x6c5d388b, 0xb222a768, 0x1bf121c5, 0x2ef76080,
|
||||
0xb0658121, 0x8331bdd3, 0x64b5cd35, 0xc3c7fbe4, 0x576e7d5e, 0x1cbdc1b2, 0x5c54b675, 0xbffd76e3,
|
||||
0x2ad7b53f, 0xe596de29, 0xc2d972db, 0xf1c92f34, 0x6af3ded6, 0xec317d66, 0x6a17bed5, 0x27750e9e,
|
||||
0x8d950cb3, 0xb07688cc, 0x17a6ddd8, 0x5bf140e0, 0xed8713e0, 0x05890caa, 0xf66e4d73, 0x5ea0347f,
|
||||
0xf535f2f5, 0x240c70f3, 0x5e922192, 0x8e59f944, 0x3185f7a7, 0x852dd342, 0x58c8e53b, 0x760071c5,
|
||||
0xadb76f78, 0x185ab80c, 0x9d84df28, 0x4d2056da, 0x69bebccc, 0xa9fcb5f8, 0xb9d3ac81, 0xcc374aac,
|
||||
0xc04e1ee9, 0x72634634, 0xb3bbf485, 0x1eb91de5, 0x5e8de602, 0x211cd561, 0xb03404e6, 0x051f3a53,
|
||||
0xb263569c, 0x96cbc54f, 0x9eaf58e6, 0x32e9f0f2, 0x370f1cd9, 0x15bf840d, 0x1dbd5d06, 0xb04d214d,
|
||||
0x6d1697ee, 0xc4b6fce1, 0x1b95f82d, 0x46979ca6, 0x0354cfc8, 0xd5950d3d, 0x10db605d, 0x18af3572,
|
||||
0x990ec7a8, 0x2a0fe87f, 0x7937dbb8, 0xee376c86, 0xcc9f9070, 0xc953caa8, 0xd5c7c2ed, 0xee4f752e,
|
||||
0x84f302f7, 0x1e08a48e, 0x44a5da35, 0x0fab83e2, 0xbb7cb9df, 0x2590afe1, 0xfef026aa, 0x83dbd643,
|
||||
0xbe916d11, 0x27f7fba9, 0x82135d43, 0x6c5fa2a4, 0xe1e1370e, 0x51534581, 0x4cd9def3, 0xd94b4990,
|
||||
0x74772379, 0x59264a1d, 0xc1dcdd8e, 0xed4ef1e9, 0xf29d901a, 0x68ecd0ad, 0x9ac31f92, 0x839a285e,
|
||||
0x46447122, 0xc0e56c6e, 0xb09a4b83, 0xa9500b90, 0xda83c4e5, 0x4175b2f8, 0xeb4ddb4a, 0x236c6f2e,
|
||||
0xeeb57a32, 0x2626e708, 0xa9d35265, 0x6ab3e9ab, 0xf12fcc1f, 0x1c317c43, 0x66c34fb3, 0xe17e58a0,
|
||||
0x0295d4a1, 0x40cd40f9, 0x72700bb0, 0xd591e61e, 0x3e96b29b, 0xb50d5db3, 0xa3715dcc, 0x3405bcb4,
|
||||
0x0e034d65, 0x210a4a2b, 0x7c302f2c, 0x24e8bef6, 0xa5135147, 0x0607ef80, 0x01f86c8f, 0x2c792c8a,
|
||||
0x6ab73133, 0x6f436006, 0x09bf22a6, 0x1fde4622, 0x9841bd1c, 0xb23a7ad7, 0xdad579a4, 0x431229e9,
|
||||
0xfa5dcb2d, 0x7da4f790, 0xa9b2c914, 0xcd191ced, 0x7a05e4aa, 0x73af1889, 0x192667b3, 0x538d4540,
|
||||
0xacdbca81, 0x6b9d9e90, 0xc0462bba, 0xfcf5a7b9, 0x7b5c2904, 0x41a83c83, 0x7e69828f, 0x328a3bab,
|
||||
0xdcd0f182, 0x1d113bcd, 0x1fb5c81c, 0x2d52afa0, 0x2d0c6111, 0x2a02ce14, 0x3fcd2c15, 0x54d574f9,
|
||||
0xde57e605, 0x85dbb53d, 0xfc7cc003, 0x769c74d9, 0x6f834a4f, 0x79b3b87e, 0xe3d7c853, 0xa83e14b2,
|
||||
0x3b1fc1ad, 0xb7dc2988, 0xb60ed652, 0xda3e3d1a, 0x5f2f680c, 0xb46e08da, 0x589b77da, 0xcef68535,
|
||||
0x1c05d7a6, 0x24572da1, 0x939b02a5, 0xccd08d13, 0xdfa22970, 0xdff7581b, 0x2d5fade6, 0x5cfd3389,
|
||||
0xce26cbb1, 0x376d7fd0, 0x02811e2e, 0xcc8030ab, 0xa7a4c9dc, 0x81db0ca7, 0x15a1bcef, 0x2045c6b5,
|
||||
0x52c2f563, 0x6c829737, 0xb4f3384f, 0xb14d2f2b, 0xe102e00a, 0xba359973, 0x6045dd8b, 0xd0a5e531,
|
||||
0xd679300f, 0xaabec63e, 0x526ad900, 0x95224f33, 0x723d6d44, 0x83584ad4, 0xa14ed869, 0x727bb03a,
|
||||
0xdde37025, 0xb29d6587, 0xc3f3971d, 0x725933c2, 0x68f3eda4, 0xf73e9fdc, 0x944afd04, 0xa4c5e05f,
|
||||
0x477f70ae, 0xffebfc90, 0xc21cff70, 0x84c68e32, 0xe82a3d6b, 0xba243867, 0x511c142f, 0x2062b8ac,
|
||||
0x274a119f, 0x772afba2, 0x88a3974d, 0x205cf0de, 0xe45d5a2a, 0x1745056b, 0x2c8138f5, 0x982938a7,
|
||||
0xfb265af9, 0x700c2cdf, 0x93e549b4, 0xb8abd353, 0xd74073e8, 0x289caf2a, 0x63e802e9, 0xc2f9adb7
|
||||
};
|
||||
|
||||
/**
|
||||
* The output sequence generated by reference ISAAC algorithm in C language.
|
||||
* For initial seeding is used SEED_2 data array.
|
||||
* 1024 signed 32-bit integers in hexadecimal representation.
|
||||
*/
|
||||
private static final int[] EXPECTED_SEQUENCE_2 = {
|
||||
0x67ae8a37, 0xa78322ea, 0xb9394933, 0x61f6e3c5, 0xbea576f1, 0xbb958f18, 0x12ce6479, 0xc593d5de,
|
||||
0xdef281a0, 0x8435bb62, 0xf20b44db, 0x8a98479a, 0xbf2b8b66, 0x1080265e, 0xf0f8f12f, 0x021fa7f3,
|
||||
0x81d2ed59, 0xb224a5f8, 0x0c1ff346, 0x92007ea8, 0x8fd1ce43, 0xeced69f5, 0x651fe09a, 0x45cf2c3e,
|
||||
0x449b2b1e, 0x4f136be5, 0x8240cc97, 0xca979afa, 0x33b6a857, 0x7300f4f3, 0x79755d71, 0xcf11dd62,
|
||||
0x916b7e04, 0x02076c0e, 0x9b4e3e68, 0x04836ed5, 0xf1b492c6, 0x887ef90c, 0x091b68f6, 0xaf7f0d3b,
|
||||
0x89d7e5c1, 0x2b28fff7, 0xe6280e4f, 0x6681a805, 0xcb270bbb, 0x8e037463, 0x31a125f7, 0x0ba3c135,
|
||||
0x7c2e8b3e, 0x6e21e06e, 0xc8b336ba, 0x08d677c3, 0x469fd05c, 0x71528649, 0x2024c602, 0x000e4f99,
|
||||
0xb03395b1, 0x0a12d960, 0x68b15274, 0x7c415c07, 0x047c739b, 0x46658905, 0x45512a3c, 0x7f4cd2ff,
|
||||
0x3d4d4ef6, 0xd7016dad, 0x6074bbf0, 0xbeaa55eb, 0xc519d326, 0x3ad349fd, 0x2fec4649, 0x14fa40ae,
|
||||
0x96b51341, 0x2bf08ef1, 0xd1d374e4, 0x44168b14, 0xb01bee9b, 0x0b3f4332, 0xc799b9da, 0x76fc7dbd,
|
||||
0x8c368a57, 0xe4cd2cad, 0xeeb0318a, 0xc2152908, 0x2b707a0e, 0x73457464, 0xc08e92a0, 0xfcdfca5b,
|
||||
0x1320ed43, 0x333b77b9, 0x2e70948a, 0xa77d94f7, 0xbc1fb9fa, 0xa8ad15a1, 0x3c47b0f4, 0x867c4a8f,
|
||||
0xb85784e0, 0x8a854e80, 0x456c8700, 0xc28f3a01, 0x415da6aa, 0x1315c6d8, 0x70a4ca70, 0xfdea940e,
|
||||
0x686fbdc9, 0xda649eba, 0x661196f7, 0x795b5d27, 0xe10c78fa, 0x2fd89cf3, 0x61e850da, 0x00c49764,
|
||||
0xee51d841, 0x00c18025, 0xdea163b3, 0x8b1b2080, 0x6abdd683, 0xe560c731, 0xc661b3e0, 0x23a3ff08,
|
||||
0xa7579919, 0xfa443cba, 0x480bd220, 0x0a11740b, 0xb4b327c7, 0x831a0840, 0xb7c50ff3, 0x4266dff1,
|
||||
0x835d0665, 0x52593038, 0x3917fb8e, 0x88c3b400, 0x05fb8823, 0xc9eaa89f, 0x6957fd17, 0x8dbcb8fe,
|
||||
0xdec10c3c, 0x918d5fd8, 0x6af8619a, 0x8f472255, 0xc2f757b7, 0x9d62e804, 0x45e0e276, 0x482597d3,
|
||||
0x06190214, 0x172b8501, 0xe91d7b8c, 0x4ee985fc, 0x3ecbf47a, 0xbbae5d98, 0x1f0bbdeb, 0x0d38208e,
|
||||
0x6d4cb3e3, 0xa70050c4, 0xf0db408e, 0xddb6f1a7, 0x4bc4bc61, 0x90e1c1db, 0x203770dc, 0x39959247,
|
||||
0xe2e0376a, 0xf70a8521, 0x81c759b2, 0x24d9915b, 0x09cc2ec3, 0x0fd0bff9, 0x58875636, 0xee78837e,
|
||||
0x025a7eee, 0x4226859f, 0x85e21806, 0x9c1328bd, 0x0522fda0, 0x585441aa, 0x366f9ea0, 0xeb70934f,
|
||||
0x0e394c41, 0xfa801419, 0x2b6d4c3e, 0xb09775fe, 0x3f0184ae, 0x3ace3518, 0xf80bf893, 0x9754753b,
|
||||
0x78c46b93, 0x281e1918, 0x0dfcc5ee, 0xc0401601, 0xf8b11ce9, 0x9f799306, 0xb65c4232, 0x12ee4f73,
|
||||
0xade72a42, 0x0ce54d71, 0xa6780e69, 0xe73bd8f9, 0xc245228f, 0x5fa2ed1a, 0x11627d1d, 0x2617ea2f,
|
||||
0xd7404db6, 0x228fb877, 0xc5379535, 0xfe00008d, 0xc5f1491e, 0x1a3bdb0e, 0x9a90cc98, 0xa0abe3f5,
|
||||
0xac7a0d18, 0x87bb3538, 0xa224baf7, 0xf2496ca4, 0x6a5b9bd6, 0x9a7da8d8, 0x72419677, 0xa36aec4d,
|
||||
0x2a08ac0d, 0xfc4d7b21, 0x25f2aad0, 0x4f7146d4, 0xb4a603bd, 0x194e9792, 0x8f60cf1c, 0xed8ae037,
|
||||
0xa47f90b1, 0x5eec55a3, 0x326c33d4, 0x6f79168f, 0xbcfc27fa, 0xd9e76d04, 0x79430e33, 0xd0c3b727,
|
||||
0xd4bb06af, 0x8805066b, 0xaaef1130, 0x04958fef, 0x2e3270f4, 0xf5a8ffe8, 0x2a089c72, 0xff411bfc,
|
||||
0xd6ed9552, 0x6253f5ef, 0x0c836c2f, 0xb79471b0, 0x127d177c, 0xf901cefa, 0xff75dc46, 0xde79ec4f,
|
||||
0xe9f1f182, 0x9d28d8cd, 0xfcc98a94, 0x227670c2, 0x46b7c48c, 0x8fd77dcb, 0x60bc6d66, 0xe775322d,
|
||||
0x0def2251, 0xf3dd14cb, 0x6c3f3468, 0x87696244, 0x10cca0be, 0x1d7fa716, 0x955b963b, 0xe53b6074,
|
||||
0x77af9ec4, 0xfc856100, 0x91a06dc7, 0x8d55e3f1, 0xf8c805a3, 0xf3a1cb7a, 0xbcd51c6d, 0x301fdcdf,
|
||||
0xdbcbcc54, 0x8b85fe57, 0x946d707e, 0x388a2ed4, 0xc4b93a5b, 0xd48631d2, 0xae2b4f28, 0x5b731392,
|
||||
0xdf6e621e, 0xc4590c30, 0xa3a23cd5, 0xbfce9899, 0x4620cff9, 0x966c8c3f, 0x7a302556, 0x3fe549fa,
|
||||
0x67533e77, 0x80250302, 0xcd899fe7, 0x694e77ea, 0x0879525d, 0xab6675e4, 0x763f8b35, 0x7684e6a1,
|
||||
0x8fa35070, 0xe9fccaf1, 0x2d7195b7, 0x85b45186, 0xab799317, 0x2c84bd2c, 0xf8354c09, 0x02d96875,
|
||||
0x8fdcc390, 0xf6af5aec, 0x2a584739, 0x8a1ba7e9, 0xea46f9b2, 0x98acd24f, 0xfc8a3a24, 0xa496eff9,
|
||||
0x625c30ea, 0xc6ea0535, 0x3ed3b5d6, 0xffcd675d, 0x0b1719f6, 0x1b1c4e7b, 0x3206a672, 0x62fc1851,
|
||||
0xa6a4c781, 0x78bbdbbe, 0x06c1c8ce, 0x5747c340, 0xfff7ab9c, 0xebaf9370, 0xf7b185a8, 0xf8309f84,
|
||||
0xfa1601de, 0xf9fc8780, 0x59c2f8bd, 0xe74fcd5b, 0xf115f57f, 0xddda3332, 0x2ee56568, 0xa2243659,
|
||||
0x9d6d578f, 0xbb507574, 0x95d44e0e, 0xdbdf2bc3, 0x0dc1b750, 0xc6a24241, 0x207d7115, 0xc337d024,
|
||||
0x3817ef9a, 0xe9f12ccf, 0x4d67fc7d, 0x3da57a2b, 0x000e09a5, 0xe739c5a2, 0x7b7e1613, 0x23d576fe,
|
||||
0x6941a210, 0x57521190, 0xdc4359c0, 0xd8eed2f8, 0x7862904f, 0xfc179a41, 0xeee2716e, 0x362cf76a,
|
||||
0x0a087072, 0x3e6e2fa9, 0xaf2a0efb, 0x221d513f, 0xf054d856, 0xc3297367, 0x1c0998c8, 0xa664172f,
|
||||
0xe2637c8e, 0xc17ac7d4, 0x0e041f43, 0x0d9c0ae4, 0x9346dacf, 0x7fb2a015, 0xe92276c2, 0x21478bfe,
|
||||
0x119e2d0c, 0x5f76aeaf, 0xbe21aaec, 0x63174d5f, 0x13b796c3, 0x0fa0eba1, 0xe2f7277a, 0x3f555b42,
|
||||
0x0215c7e4, 0x96266efa, 0x2953a4d1, 0xadfc171a, 0x396234a7, 0x560c0279, 0xefa6d2c6, 0xf48d9b5a,
|
||||
0x4131c7b1, 0x9e302f70, 0x637c9f23, 0x22637330, 0x09927e76, 0x0898d1d6, 0x1b797274, 0x9ad491a2,
|
||||
0xa2df3627, 0x012c3ed0, 0xc19c09d7, 0xa2fdaf56, 0x5b91f8fd, 0x3b7c49c9, 0x25694d29, 0xd7b42e9c,
|
||||
0xa7be0053, 0xa91f1761, 0xd89e8b2a, 0x67846097, 0x76bd4006, 0xb8eb0712, 0x859bf877, 0xca42d70c,
|
||||
0x24e80a69, 0xd92bc598, 0x55498c1e, 0x86deba8b, 0xf7c340b7, 0xa36caa12, 0x0631ddec, 0xc0146fe8,
|
||||
0x2f959ef3, 0xf8400f0c, 0x58f676a0, 0x4ae4fe13, 0x9c4af056, 0x9e6f19d6, 0x12a9eb69, 0x1aeed54e,
|
||||
0x34c91114, 0x97128045, 0x920d1f59, 0xffe7fbaa, 0x2db4a671, 0x6e6ff7aa, 0xd40d46bd, 0x1578f939,
|
||||
0x15c5cbc6, 0xff356fd0, 0xd5d1680c, 0x5b11d14d, 0xe75541c0, 0x0fe2e2ba, 0x3ad55308, 0x8f036a69,
|
||||
0xa9bfc3cd, 0x87685338, 0x510092b4, 0x1f66622a, 0x996337b2, 0xc531891f, 0x98371a93, 0xd9630100,
|
||||
0x513ff133, 0xcf8381da, 0xed12e8e9, 0xe3ce7c7b, 0x8f731ab5, 0x511ba7c2, 0x9d754e87, 0x244603ac,
|
||||
0xfd9985e1, 0xc1581765, 0x84e50a12, 0xa0ab0034, 0x63ee60c2, 0xdf5ab248, 0x09b42202, 0xca87f896,
|
||||
0xca6ae5f0, 0xa569d829, 0x977cf29b, 0xd56a2a2f, 0x85ad1532, 0xfa2a131a, 0x00784081, 0x81f0e466,
|
||||
0xebd340d3, 0xc37ad0e4, 0xd0aa6d7a, 0x36d2551f, 0xd6ff8448, 0xc7b89445, 0xa43421ad, 0x3be75400,
|
||||
0x557a61ef, 0x0f519b14, 0x56503579, 0x1c8d164d, 0x0dcef35b, 0x3d9f1f2a, 0x56d056f2, 0x5d8fd4ec,
|
||||
0xa481a350, 0x7cadd9c0, 0x70375ce2, 0x83263d2a, 0x5826ea3b, 0xfa523ce7, 0x50c9438b, 0x74fca95d,
|
||||
0x62967ef5, 0x11fd6429, 0xcbb8e28c, 0x67fb9e81, 0xdc9e1147, 0xa29672f7, 0x1cf310f7, 0xb1e1d8e6,
|
||||
0x3f862ff3, 0x6ade0327, 0xa92f3686, 0xed79f165, 0x359e1620, 0x36c68936, 0xe46fe521, 0x0c5e36b0,
|
||||
0x6d9d9cdb, 0xc095eecd, 0x566dd305, 0x6d96cd36, 0x5d115a80, 0x2a9489a8, 0xdd067488, 0x73acf831,
|
||||
0x7392c0f0, 0x30707838, 0x92826042, 0x67c54548, 0xf830434d, 0xebe67854, 0xaefc9a41, 0xcabf703f,
|
||||
0x5242c77f, 0x1f3867a9, 0x48174739, 0x8657c39e, 0xa11247e2, 0xb4e6624d, 0xc7ffe78a, 0x1e11a841,
|
||||
0x6690244b, 0x8dcc9292, 0x5ce4dcc4, 0xebcba02d, 0x2ef6503d, 0x4fb880bc, 0xb949a759, 0x7bb18a1e,
|
||||
0x5973d2e8, 0x577ad8a6, 0xa9d4992e, 0x1a248a0c, 0xcc4450ed, 0x7e0178d3, 0xe98a8f3f, 0x209fb330,
|
||||
0xf7bf40fc, 0x632231b3, 0x7055fdaf, 0x7719e655, 0xf8d49413, 0xc200aa04, 0x8a41183a, 0xdfa217c1,
|
||||
0xcd0c165d, 0x08fec61c, 0xef608048, 0xe19fae2c, 0xedc6f3ea, 0x859a69f9, 0x5f96c76d, 0x571aec69,
|
||||
0x9cfe7fa4, 0x692baf70, 0xbb143cb4, 0xe8968678, 0xfcb77411, 0x02d3268d, 0xcdc3daa3, 0x514e78e9,
|
||||
0xa231a480, 0x8ac10400, 0xe19a2ca1, 0xfa790fe1, 0x808fec9c, 0xe4760960, 0x62e9d051, 0x5c4b006b,
|
||||
0x22eb9703, 0x426b5907, 0xfa1cd338, 0xa3b4811a, 0xad6185c1, 0x349efbc0, 0xeee28d42, 0x02531fc5,
|
||||
0xd11b2c4d, 0x5b3bf865, 0xf4823687, 0x4f92b6b7, 0xfb641c60, 0x0c526fa9, 0x42438de8, 0xd5cbf7a0,
|
||||
0x54ad0d1f, 0xb4e63f09, 0x666285eb, 0xe7ec0275, 0x57e7225a, 0xafe6b0e3, 0x17431cd7, 0x33bc9204,
|
||||
0x8a9cbdde, 0x94d8fe7d, 0xc943f36c, 0x1348c3c6, 0x43cf9b8c, 0x5a84ae20, 0x6d372dea, 0xdb0b3c92,
|
||||
0xf0f2a72d, 0x473a1fe7, 0x062416df, 0x0a12c61c, 0x3680c102, 0x8d0189db, 0x0824325f, 0xffb97ead,
|
||||
0x0d8d353f, 0x4a4e6ec2, 0x76243bb7, 0xdabfbeee, 0xcd8410d7, 0xa30f17c3, 0x2b59ceef, 0xda27f7c0,
|
||||
0x791d813b, 0xc0516741, 0xb363e4ff, 0x31ddbfb7, 0x49db1590, 0xd843513c, 0x8d317a75, 0xb24387df,
|
||||
0x63fd4066, 0xa0fce498, 0x7b42de97, 0x30eddc0c, 0x071ad222, 0x3a9054c4, 0x5ce35298, 0x375be64b,
|
||||
0x10af32c8, 0xa999ade1, 0xfa9f4d31, 0xfbe24a2a, 0x4c92714b, 0xcce3056a, 0xa81d616a, 0x3bb49213,
|
||||
0x72fd2b0e, 0x1b46d17e, 0x92159bc7, 0x7462e172, 0x4fdc3e05, 0xf309c063, 0x9133532c, 0xe62d9341,
|
||||
0x681a4871, 0xb1598525, 0x498ca388, 0x96a7ea81, 0x791c8a85, 0x2a33a1e2, 0x1e6abc87, 0xb21a4878,
|
||||
0x65fac53b, 0x59162ae1, 0x22858a30, 0x40f4e569, 0xe5cb0023, 0x626cd2a0, 0xfe6d8fc8, 0xbb7ed7c3,
|
||||
0x9a557393, 0xd0ff5e60, 0x2a20ed9b, 0x4eaafb5a, 0xbe9425bd, 0x63620ce1, 0x31ea24ed, 0x082e426a,
|
||||
0x7ff35a73, 0xa67fbaa9, 0xd2e3c5b9, 0x1a90e96a, 0x71f19184, 0xb836b88b, 0xe51fa187, 0x42576438,
|
||||
0x58d28776, 0x47bd92a3, 0x09816862, 0x295138ef, 0x23ab2bb1, 0xd7c584e0, 0x1793062f, 0xcc47e852,
|
||||
0xc2eb9703, 0xe6812d93, 0xa4aa4d2e, 0x7f635b79, 0xa7407b29, 0x9724c087, 0x406e08ce, 0x6bf1d8b7,
|
||||
0x9ef5b815, 0xf2c6f094, 0x86269ca2, 0x17fdaa4f, 0x9b645b61, 0x701bbbeb, 0x8de7bcb7, 0xd468266a,
|
||||
0x48df44ae, 0x570b08ca, 0x7a5ba43b, 0xfc927312, 0x3461a3dd, 0x0ffe5943, 0x87060375, 0x8d8afed7,
|
||||
0x83d20387, 0x77eabb51, 0xf86d045b, 0x71a47537, 0xa4485ea8, 0xfd2b6ac3, 0xb4ba1fcf, 0x31dcee82,
|
||||
0x8b41cdf6, 0xeacde42b, 0x02de5fbb, 0xb6311aa8, 0x1596ee5d, 0x355cc39d, 0xbe1a87c1, 0x01e1df07,
|
||||
0xfe413d46, 0x5e5e13ab, 0x30233fd6, 0x99449292, 0x34955dcc, 0x1f37d394, 0xd43639bd, 0x65c98eee,
|
||||
0x67b85593, 0x1660b2a1, 0xfd86e9a0, 0x33bb6e5a, 0xdd5892fb, 0xa6832091, 0xd077d216, 0x353bfe9a,
|
||||
0xb4a10726, 0xca1a536e, 0xed8af6c1, 0x41d167d1, 0x5f554941, 0x93f4032a, 0x83d83ae5, 0xc8866a05,
|
||||
0xc36d1e1f, 0x95a082c5, 0xd85e6cad, 0x302bc384, 0x41fb8717, 0x61221cc8, 0xce9a44cd, 0x2884ec21,
|
||||
0x9712152d, 0x419e4939, 0x32367b47, 0x238ee432, 0xd27f0b8e, 0xa3eaed24, 0x1eefd0a9, 0xf38a2400,
|
||||
0x72c0d4b2, 0x8bdbdec1, 0x563a2b59, 0x0d50177b, 0xb01576ef, 0x7dd9f33e, 0x7905c120, 0x461712d6,
|
||||
0x78265e93, 0x54a91f0b, 0xb88eb9c0, 0x9d8997af, 0xcb1d1296, 0xfa0a3a77, 0x5bb26dd9, 0xf6da78df,
|
||||
0x53b8e80c, 0xc55cdaf6, 0x871a3971, 0x0bd8d322, 0xfa9e0a9c, 0x95949e0e, 0xe94f0edb, 0x15e06b25,
|
||||
0x8b3e34cc, 0x980261a9, 0x3a8fe440, 0xc72330aa, 0xbff5c8b6, 0x486a08e6, 0x6b3f0668, 0x53c90761,
|
||||
0x1dc2374b, 0xba623bb6, 0x720d9fff, 0x8454fada, 0x29f09563, 0x6512330e, 0x84370042, 0xda55c14b,
|
||||
0xe6397b27, 0xdb03bcc7, 0xd6e27986, 0x483ad4f2, 0xe0e2c39a, 0x459e6792, 0x03c120ec, 0x13df7847,
|
||||
0xc3ee77e1, 0xbcee7cd4, 0xdb3734ec, 0x0e19ebb2, 0x1501517a, 0x815190f7, 0xea30ba2c, 0xed58523c,
|
||||
0x9dc64c08, 0x58d8753f, 0x1fa771c5, 0x7721fb09, 0xc64d1f60, 0xf407dc18, 0x6fdb1e33, 0x89abccb8,
|
||||
0x2fab8715, 0xd8ee352e, 0x41bfa764, 0xda0267ee, 0x65794080, 0xe3095d65, 0x08e2148b, 0x173103b5,
|
||||
0x55673978, 0x8d76b213, 0x6ed42e4b, 0xbe589395, 0xcf4c4d8a, 0xd331b237, 0x0af2f4cb, 0x202be7fa,
|
||||
0x2e87bc27, 0x140a95df, 0xa0d1ef7e, 0x1031da30, 0x630f3ea6, 0x0e3b0991, 0xba7c0462, 0xca8a192c,
|
||||
0x668417e2, 0x2c6e8ec5, 0x3f2e4372, 0x310927e9, 0xa87b5f4e, 0x21e3f285, 0x66aab4be, 0x96804f73,
|
||||
0x097c363b, 0x76445811, 0xaf92fb77, 0x660010b7, 0x3ff5abbb, 0xdaa505d0, 0x17dc3488, 0x45dac66a,
|
||||
0xa834d6eb, 0xacf0641f, 0x05576174, 0x28bf1858, 0x08829e92, 0xd3c5d530, 0x6acd00b2, 0xf36c0645,
|
||||
0x4385cae7, 0x93b11f88, 0x3dfe1da7, 0x2d5df9d8, 0xd51d498f, 0x1d122b84, 0x2ca7619f, 0x670fba3a,
|
||||
0xa59f3019, 0xd25ade01, 0x43ef2f88, 0x05cf6af4, 0x6fc3b5e0, 0x305a309e, 0xb7bce57b, 0x49c55693,
|
||||
0xd59bd6d0, 0xdf13274c, 0xa5640917, 0xb8e88520, 0xf81fb865, 0x245967cf, 0x64420112, 0x97720fd0,
|
||||
0x0ef913f8, 0x9fcf14f4, 0x99a86a60, 0x150ae075, 0x1b4be51e, 0x12fe7368, 0x23781feb, 0x3657b0c3,
|
||||
0x90f84f92, 0x082f626d, 0xf057cef1, 0xf04fc2c1, 0x8767f311, 0x240ab838, 0x160564c0, 0x96f4460d,
|
||||
0x2c7e5c83, 0xb44e6da1, 0x43f86ae1, 0xe3afdf03, 0x34173462, 0x197d8030, 0xb02d6ae7, 0x0cec076c,
|
||||
0x0fb9d05e, 0x1fa74d99, 0x03f9636e, 0x03afa44d, 0x79ceb46c, 0x8b9e3158, 0xad87d846, 0xaf794612,
|
||||
0xdd00ae31, 0xde8d63de, 0x229c5e66, 0x2df46e14, 0x3cbb35d1, 0x9832a55b, 0xaff3c01c, 0xaf4cc2be,
|
||||
0x05095c2b, 0xee6be44f, 0x7b9bd378, 0x09a5f11f, 0xfddc340a, 0x010da0fa, 0x60874e63, 0x9f03a38b,
|
||||
0xddfe1c05, 0x8dadcc16, 0x6df97114, 0xe0779adc, 0x8de82987, 0x83cca69c, 0x38b19e7c, 0xebc30d07,
|
||||
0xb36f46cc, 0xee4d1453, 0x7522c310, 0x3a43d376, 0xab400f15, 0x4fedfa99, 0x02e7323e, 0x4c57f680,
|
||||
0xe4190ae5, 0x6a5bba49, 0xd3c223d8, 0x1b87ab96, 0xaef4795f, 0xf457cd2d, 0x2bae8689, 0xa229c48f,
|
||||
0x41bd5e74, 0x25cb3da8, 0xfd47e4d0, 0x0a241ffc, 0x16c0dba7, 0x6f1469fd, 0x810c16da, 0x66a7b33c,
|
||||
0xe6c9e001, 0x9ccefde6, 0xd24f7adc, 0x1bcc8980, 0x37084252, 0xb779d5cd, 0x52e456d0, 0x313ba4de,
|
||||
0xffb09943, 0x0e9d4e1f, 0x5a3c51ac, 0x6f055f04, 0xb2ac9a26, 0xb7fac64f, 0x27cc0c8d, 0x342bbac3
|
||||
};
|
||||
|
||||
@Test
|
||||
public void testReference() {
|
||||
ISAACRandom isaacRandom = new ISAACRandom(SEED_1);
|
||||
|
||||
int[] actualSequence = getActualSequence(isaacRandom);
|
||||
Assert.assertArrayEquals(EXPECTED_SEQUENCE_1, actualSequence);
|
||||
|
||||
isaacRandom.setSeed(SEED_2);
|
||||
actualSequence = getActualSequence(isaacRandom);
|
||||
Assert.assertArrayEquals(EXPECTED_SEQUENCE_2, actualSequence);
|
||||
|
||||
}
|
||||
|
||||
private int[] getActualSequence(ISAACRandom isaacRandom) {
|
||||
int[] actualSequence = new int[1024];
|
||||
for (int i = 0; i < actualSequence.length; i++) {
|
||||
actualSequence[i] = isaacRandom.nextInt();
|
||||
}
|
||||
return actualSequence;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
public class JDKRandomGeneratorTest extends RandomGeneratorAbstractTest {
|
||||
|
||||
@Override
|
||||
protected RandomGenerator makeGenerator() {
|
||||
final long seed = 111;
|
||||
return new JDKRandomGenerator(seed);
|
||||
}
|
||||
}
|
|
@ -1,306 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import org.apache.commons.math4.random.MersenneTwister;
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MersenneTwisterTest extends RandomGeneratorAbstractTest {
|
||||
|
||||
@Override
|
||||
protected RandomGenerator makeGenerator() {
|
||||
return new MersenneTwister(111);
|
||||
}
|
||||
|
||||
// TODO: Some of the tests moved up to RandomGeneratorAbstractTest tested alternative seeding / constructors
|
||||
// Tests exercising these features directly should be added to this class.
|
||||
|
||||
@Test
|
||||
public void testMakotoNishimura() {
|
||||
MersenneTwister mt = new MersenneTwister(new int[] {0x123, 0x234, 0x345, 0x456});
|
||||
long[] refInt = {
|
||||
1067595299l, 955945823l, 477289528l, 4107218783l, 4228976476l, 3344332714l, 3355579695l, 227628506l,
|
||||
810200273l, 2591290167l, 2560260675l, 3242736208l, 646746669l, 1479517882l, 4245472273l, 1143372638l,
|
||||
3863670494l, 3221021970l, 1773610557l, 1138697238l, 1421897700l, 1269916527l, 2859934041l, 1764463362l,
|
||||
3874892047l, 3965319921l, 72549643l, 2383988930l, 2600218693l, 3237492380l, 2792901476l, 725331109l,
|
||||
605841842l, 271258942l, 715137098l, 3297999536l, 1322965544l, 4229579109l, 1395091102l, 3735697720l,
|
||||
2101727825l, 3730287744l, 2950434330l, 1661921839l, 2895579582l, 2370511479l, 1004092106l, 2247096681l,
|
||||
2111242379l, 3237345263l, 4082424759l, 219785033l, 2454039889l, 3709582971l, 835606218l, 2411949883l,
|
||||
2735205030l, 756421180l, 2175209704l, 1873865952l, 2762534237l, 4161807854l, 3351099340l, 181129879l,
|
||||
3269891896l, 776029799l, 2218161979l, 3001745796l, 1866825872l, 2133627728l, 34862734l, 1191934573l,
|
||||
3102311354l, 2916517763l, 1012402762l, 2184831317l, 4257399449l, 2899497138l, 3818095062l, 3030756734l,
|
||||
1282161629l, 420003642l, 2326421477l, 2741455717l, 1278020671l, 3744179621l, 271777016l, 2626330018l,
|
||||
2560563991l, 3055977700l, 4233527566l, 1228397661l, 3595579322l, 1077915006l, 2395931898l, 1851927286l,
|
||||
3013683506l, 1999971931l, 3006888962l, 1049781534l, 1488758959l, 3491776230l, 104418065l, 2448267297l,
|
||||
3075614115l, 3872332600l, 891912190l, 3936547759l, 2269180963l, 2633455084l, 1047636807l, 2604612377l,
|
||||
2709305729l, 1952216715l, 207593580l, 2849898034l, 670771757l, 2210471108l, 467711165l, 263046873l,
|
||||
3569667915l, 1042291111l, 3863517079l, 1464270005l, 2758321352l, 3790799816l, 2301278724l, 3106281430l,
|
||||
7974801l, 2792461636l, 555991332l, 621766759l, 1322453093l, 853629228l, 686962251l, 1455120532l,
|
||||
957753161l, 1802033300l, 1021534190l, 3486047311l, 1902128914l, 3701138056l, 4176424663l, 1795608698l,
|
||||
560858864l, 3737752754l, 3141170998l, 1553553385l, 3367807274l, 711546358l, 2475125503l, 262969859l,
|
||||
251416325l, 2980076994l, 1806565895l, 969527843l, 3529327173l, 2736343040l, 2987196734l, 1649016367l,
|
||||
2206175811l, 3048174801l, 3662503553l, 3138851612l, 2660143804l, 1663017612l, 1816683231l, 411916003l,
|
||||
3887461314l, 2347044079l, 1015311755l, 1203592432l, 2170947766l, 2569420716l, 813872093l, 1105387678l,
|
||||
1431142475l, 220570551l, 4243632715l, 4179591855l, 2607469131l, 3090613241l, 282341803l, 1734241730l,
|
||||
1391822177l, 1001254810l, 827927915l, 1886687171l, 3935097347l, 2631788714l, 3905163266l, 110554195l,
|
||||
2447955646l, 3717202975l, 3304793075l, 3739614479l, 3059127468l, 953919171l, 2590123714l, 1132511021l,
|
||||
3795593679l, 2788030429l, 982155079l, 3472349556l, 859942552l, 2681007391l, 2299624053l, 647443547l,
|
||||
233600422l, 608168955l, 3689327453l, 1849778220l, 1608438222l, 3968158357l, 2692977776l, 2851872572l,
|
||||
246750393l, 3582818628l, 3329652309l, 4036366910l, 1012970930l, 950780808l, 3959768744l, 2538550045l,
|
||||
191422718l, 2658142375l, 3276369011l, 2927737484l, 1234200027l, 1920815603l, 3536074689l, 1535612501l,
|
||||
2184142071l, 3276955054l, 428488088l, 2378411984l, 4059769550l, 3913744741l, 2732139246l, 64369859l,
|
||||
3755670074l, 842839565l, 2819894466l, 2414718973l, 1010060670l, 1839715346l, 2410311136l, 152774329l,
|
||||
3485009480l, 4102101512l, 2852724304l, 879944024l, 1785007662l, 2748284463l, 1354768064l, 3267784736l,
|
||||
2269127717l, 3001240761l, 3179796763l, 895723219l, 865924942l, 4291570937l, 89355264l, 1471026971l,
|
||||
4114180745l, 3201939751l, 2867476999l, 2460866060l, 3603874571l, 2238880432l, 3308416168l, 2072246611l,
|
||||
2755653839l, 3773737248l, 1709066580l, 4282731467l, 2746170170l, 2832568330l, 433439009l, 3175778732l,
|
||||
26248366l, 2551382801l, 183214346l, 3893339516l, 1928168445l, 1337157619l, 3429096554l, 3275170900l,
|
||||
1782047316l, 4264403756l, 1876594403l, 4289659572l, 3223834894l, 1728705513l, 4068244734l, 2867840287l,
|
||||
1147798696l, 302879820l, 1730407747l, 1923824407l, 1180597908l, 1569786639l, 198796327l, 560793173l,
|
||||
2107345620l, 2705990316l, 3448772106l, 3678374155l, 758635715l, 884524671l, 486356516l, 1774865603l,
|
||||
3881226226l, 2635213607l, 1181121587l, 1508809820l, 3178988241l, 1594193633l, 1235154121l, 326117244l,
|
||||
2304031425l, 937054774l, 2687415945l, 3192389340l, 2003740439l, 1823766188l, 2759543402l, 10067710l,
|
||||
1533252662l, 4132494984l, 82378136l, 420615890l, 3467563163l, 541562091l, 3535949864l, 2277319197l,
|
||||
3330822853l, 3215654174l, 4113831979l, 4204996991l, 2162248333l, 3255093522l, 2219088909l, 2978279037l,
|
||||
255818579l, 2859348628l, 3097280311l, 2569721123l, 1861951120l, 2907080079l, 2719467166l, 998319094l,
|
||||
2521935127l, 2404125338l, 259456032l, 2086860995l, 1839848496l, 1893547357l, 2527997525l, 1489393124l,
|
||||
2860855349l, 76448234l, 2264934035l, 744914583l, 2586791259l, 1385380501l, 66529922l, 1819103258l,
|
||||
1899300332l, 2098173828l, 1793831094l, 276463159l, 360132945l, 4178212058l, 595015228l, 177071838l,
|
||||
2800080290l, 1573557746l, 1548998935l, 378454223l, 1460534296l, 1116274283l, 3112385063l, 3709761796l,
|
||||
827999348l, 3580042847l, 1913901014l, 614021289l, 4278528023l, 1905177404l, 45407939l, 3298183234l,
|
||||
1184848810l, 3644926330l, 3923635459l, 1627046213l, 3677876759l, 969772772l, 1160524753l, 1522441192l,
|
||||
452369933l, 1527502551l, 832490847l, 1003299676l, 1071381111l, 2891255476l, 973747308l, 4086897108l,
|
||||
1847554542l, 3895651598l, 2227820339l, 1621250941l, 2881344691l, 3583565821l, 3510404498l, 849362119l,
|
||||
862871471l, 797858058l, 2867774932l, 2821282612l, 3272403146l, 3997979905l, 209178708l, 1805135652l,
|
||||
6783381l, 2823361423l, 792580494l, 4263749770l, 776439581l, 3798193823l, 2853444094l, 2729507474l,
|
||||
1071873341l, 1329010206l, 1289336450l, 3327680758l, 2011491779l, 80157208l, 922428856l, 1158943220l,
|
||||
1667230961l, 2461022820l, 2608845159l, 387516115l, 3345351910l, 1495629111l, 4098154157l, 3156649613l,
|
||||
3525698599l, 4134908037l, 446713264l, 2137537399l, 3617403512l, 813966752l, 1157943946l, 3734692965l,
|
||||
1680301658l, 3180398473l, 3509854711l, 2228114612l, 1008102291l, 486805123l, 863791847l, 3189125290l,
|
||||
1050308116l, 3777341526l, 4291726501l, 844061465l, 1347461791l, 2826481581l, 745465012l, 2055805750l,
|
||||
4260209475l, 2386693097l, 2980646741l, 447229436l, 2077782664l, 1232942813l, 4023002732l, 1399011509l,
|
||||
3140569849l, 2579909222l, 3794857471l, 900758066l, 2887199683l, 1720257997l, 3367494931l, 2668921229l,
|
||||
955539029l, 3818726432l, 1105704962l, 3889207255l, 2277369307l, 2746484505l, 1761846513l, 2413916784l,
|
||||
2685127085l, 4240257943l, 1166726899l, 4215215715l, 3082092067l, 3960461946l, 1663304043l, 2087473241l,
|
||||
4162589986l, 2507310778l, 1579665506l, 767234210l, 970676017l, 492207530l, 1441679602l, 1314785090l,
|
||||
3262202570l, 3417091742l, 1561989210l, 3011406780l, 1146609202l, 3262321040l, 1374872171l, 1634688712l,
|
||||
1280458888l, 2230023982l, 419323804l, 3262899800l, 39783310l, 1641619040l, 1700368658l, 2207946628l,
|
||||
2571300939l, 2424079766l, 780290914l, 2715195096l, 3390957695l, 163151474l, 2309534542l, 1860018424l,
|
||||
555755123l, 280320104l, 1604831083l, 2713022383l, 1728987441l, 3639955502l, 623065489l, 3828630947l,
|
||||
4275479050l, 3516347383l, 2343951195l, 2430677756l, 635534992l, 3868699749l, 808442435l, 3070644069l,
|
||||
4282166003l, 2093181383l, 2023555632l, 1568662086l, 3422372620l, 4134522350l, 3016979543l, 3259320234l,
|
||||
2888030729l, 3185253876l, 4258779643l, 1267304371l, 1022517473l, 815943045l, 929020012l, 2995251018l,
|
||||
3371283296l, 3608029049l, 2018485115l, 122123397l, 2810669150l, 1411365618l, 1238391329l, 1186786476l,
|
||||
3155969091l, 2242941310l, 1765554882l, 279121160l, 4279838515l, 1641578514l, 3796324015l, 13351065l,
|
||||
103516986l, 1609694427l, 551411743l, 2493771609l, 1316337047l, 3932650856l, 4189700203l, 463397996l,
|
||||
2937735066l, 1855616529l, 2626847990l, 55091862l, 3823351211l, 753448970l, 4045045500l, 1274127772l,
|
||||
1124182256l, 92039808l, 2126345552l, 425973257l, 386287896l, 2589870191l, 1987762798l, 4084826973l,
|
||||
2172456685l, 3366583455l, 3602966653l, 2378803535l, 2901764433l, 3716929006l, 3710159000l, 2653449155l,
|
||||
3469742630l, 3096444476l, 3932564653l, 2595257433l, 318974657l, 3146202484l, 853571438l, 144400272l,
|
||||
3768408841l, 782634401l, 2161109003l, 570039522l, 1886241521l, 14249488l, 2230804228l, 1604941699l,
|
||||
3928713335l, 3921942509l, 2155806892l, 134366254l, 430507376l, 1924011722l, 276713377l, 196481886l,
|
||||
3614810992l, 1610021185l, 1785757066l, 851346168l, 3761148643l, 2918835642l, 3364422385l, 3012284466l,
|
||||
3735958851l, 2643153892l, 3778608231l, 1164289832l, 205853021l, 2876112231l, 3503398282l, 3078397001l,
|
||||
3472037921l, 1748894853l, 2740861475l, 316056182l, 1660426908l, 168885906l, 956005527l, 3984354789l,
|
||||
566521563l, 1001109523l, 1216710575l, 2952284757l, 3834433081l, 3842608301l, 2467352408l, 3974441264l,
|
||||
3256601745l, 1409353924l, 1329904859l, 2307560293l, 3125217879l, 3622920184l, 3832785684l, 3882365951l,
|
||||
2308537115l, 2659155028l, 1450441945l, 3532257603l, 3186324194l, 1225603425l, 1124246549l, 175808705l,
|
||||
3009142319l, 2796710159l, 3651990107l, 160762750l, 1902254979l, 1698648476l, 1134980669l, 497144426l,
|
||||
3302689335l, 4057485630l, 3603530763l, 4087252587l, 427812652l, 286876201l, 823134128l, 1627554964l,
|
||||
3745564327l, 2589226092l, 4202024494l, 62878473l, 3275585894l, 3987124064l, 2791777159l, 1916869511l,
|
||||
2585861905l, 1375038919l, 1403421920l, 60249114l, 3811870450l, 3021498009l, 2612993202l, 528933105l,
|
||||
2757361321l, 3341402964l, 2621861700l, 273128190l, 4015252178l, 3094781002l, 1621621288l, 2337611177l,
|
||||
1796718448l, 1258965619l, 4241913140l, 2138560392l, 3022190223l, 4174180924l, 450094611l, 3274724580l,
|
||||
617150026l, 2704660665l, 1469700689l, 1341616587l, 356715071l, 1188789960l, 2278869135l, 1766569160l,
|
||||
2795896635l, 57824704l, 2893496380l, 1235723989l, 1630694347l, 3927960522l, 428891364l, 1814070806l,
|
||||
2287999787l, 4125941184l, 3968103889l, 3548724050l, 1025597707l, 1404281500l, 2002212197l, 92429143l,
|
||||
2313943944l, 2403086080l, 3006180634l, 3561981764l, 1671860914l, 1768520622l, 1803542985l, 844848113l,
|
||||
3006139921l, 1410888995l, 1157749833l, 2125704913l, 1789979528l, 1799263423l, 741157179l, 2405862309l,
|
||||
767040434l, 2655241390l, 3663420179l, 2172009096l, 2511931187l, 1680542666l, 231857466l, 1154981000l,
|
||||
157168255l, 1454112128l, 3505872099l, 1929775046l, 2309422350l, 2143329496l, 2960716902l, 407610648l,
|
||||
2938108129l, 2581749599l, 538837155l, 2342628867l, 430543915l, 740188568l, 1937713272l, 3315215132l,
|
||||
2085587024l, 4030765687l, 766054429l, 3517641839l, 689721775l, 1294158986l, 1753287754l, 4202601348l,
|
||||
1974852792l, 33459103l, 3568087535l, 3144677435l, 1686130825l, 4134943013l, 3005738435l, 3599293386l,
|
||||
426570142l, 754104406l, 3660892564l, 1964545167l, 829466833l, 821587464l, 1746693036l, 1006492428l,
|
||||
1595312919l, 1256599985l, 1024482560l, 1897312280l, 2902903201l, 691790057l, 1037515867l, 3176831208l,
|
||||
1968401055l, 2173506824l, 1089055278l, 1748401123l, 2941380082l, 968412354l, 1818753861l, 2973200866l,
|
||||
3875951774l, 1119354008l, 3988604139l, 1647155589l, 2232450826l, 3486058011l, 3655784043l, 3759258462l,
|
||||
847163678l, 1082052057l, 989516446l, 2871541755l, 3196311070l, 3929963078l, 658187585l, 3664944641l,
|
||||
2175149170l, 2203709147l, 2756014689l, 2456473919l, 3890267390l, 1293787864l, 2830347984l, 3059280931l,
|
||||
4158802520l, 1561677400l, 2586570938l, 783570352l, 1355506163l, 31495586l, 3789437343l, 3340549429l,
|
||||
2092501630l, 896419368l, 671715824l, 3530450081l, 3603554138l, 1055991716l, 3442308219l, 1499434728l,
|
||||
3130288473l, 3639507000l, 17769680l, 2259741420l, 487032199l, 4227143402l, 3693771256l, 1880482820l,
|
||||
3924810796l, 381462353l, 4017855991l, 2452034943l, 2736680833l, 2209866385l, 2128986379l, 437874044l,
|
||||
595759426l, 641721026l, 1636065708l, 3899136933l, 629879088l, 3591174506l, 351984326l, 2638783544l,
|
||||
2348444281l, 2341604660l, 2123933692l, 143443325l, 1525942256l, 364660499l, 599149312l, 939093251l,
|
||||
1523003209l, 106601097l, 376589484l, 1346282236l, 1297387043l, 764598052l, 3741218111l, 933457002l,
|
||||
1886424424l, 3219631016l, 525405256l, 3014235619l, 323149677l, 2038881721l, 4100129043l, 2851715101l,
|
||||
2984028078l, 1888574695l, 2014194741l, 3515193880l, 4180573530l, 3461824363l, 2641995497l, 3179230245l,
|
||||
2902294983l, 2217320456l, 4040852155l, 1784656905l, 3311906931l, 87498458l, 2752971818l, 2635474297l,
|
||||
2831215366l, 3682231106l, 2920043893l, 3772929704l, 2816374944l, 309949752l, 2383758854l, 154870719l,
|
||||
385111597l, 1191604312l, 1840700563l, 872191186l, 2925548701l, 1310412747l, 2102066999l, 1504727249l,
|
||||
3574298750l, 1191230036l, 3330575266l, 3180292097l, 3539347721l, 681369118l, 3305125752l, 3648233597l,
|
||||
950049240l, 4173257693l, 1760124957l, 512151405l, 681175196l, 580563018l, 1169662867l, 4015033554l,
|
||||
2687781101l, 699691603l, 2673494188l, 1137221356l, 123599888l, 472658308l, 1053598179l, 1012713758l,
|
||||
3481064843l, 3759461013l, 3981457956l, 3830587662l, 1877191791l, 3650996736l, 988064871l, 3515461600l,
|
||||
4089077232l, 2225147448l, 1249609188l, 2643151863l, 3896204135l, 2416995901l, 1397735321l, 3460025646l
|
||||
};
|
||||
double[] refDouble = {
|
||||
0.76275443, 0.99000644, 0.98670464, 0.10143112, 0.27933125, 0.69867227, 0.94218740, 0.03427201,
|
||||
0.78842173, 0.28180608, 0.92179002, 0.20785655, 0.54534773, 0.69644020, 0.38107718, 0.23978165,
|
||||
0.65286910, 0.07514568, 0.22765211, 0.94872929, 0.74557914, 0.62664415, 0.54708246, 0.90959343,
|
||||
0.42043116, 0.86334511, 0.19189126, 0.14718544, 0.70259889, 0.63426346, 0.77408121, 0.04531601,
|
||||
0.04605807, 0.88595519, 0.69398270, 0.05377184, 0.61711170, 0.05565708, 0.10133577, 0.41500776,
|
||||
0.91810699, 0.22320679, 0.23353705, 0.92871862, 0.98897234, 0.19786706, 0.80558809, 0.06961067,
|
||||
0.55840445, 0.90479405, 0.63288060, 0.95009721, 0.54948447, 0.20645042, 0.45000959, 0.87050869,
|
||||
0.70806991, 0.19406895, 0.79286390, 0.49332866, 0.78483914, 0.75145146, 0.12341941, 0.42030252,
|
||||
0.16728160, 0.59906494, 0.37575460, 0.97815160, 0.39815952, 0.43595080, 0.04952478, 0.33917805,
|
||||
0.76509902, 0.61034321, 0.90654701, 0.92915732, 0.85365931, 0.18812377, 0.65913428, 0.28814566,
|
||||
0.59476081, 0.27835931, 0.60722542, 0.68310435, 0.69387186, 0.03699800, 0.65897714, 0.17527003,
|
||||
0.02889304, 0.86777366, 0.12352068, 0.91439461, 0.32022990, 0.44445731, 0.34903686, 0.74639273,
|
||||
0.65918367, 0.92492794, 0.31872642, 0.77749724, 0.85413832, 0.76385624, 0.32744211, 0.91326300,
|
||||
0.27458185, 0.22190155, 0.19865383, 0.31227402, 0.85321225, 0.84243342, 0.78544200, 0.71854080,
|
||||
0.92503892, 0.82703064, 0.88306297, 0.47284073, 0.70059042, 0.48003761, 0.38671694, 0.60465770,
|
||||
0.41747204, 0.47163243, 0.72750808, 0.65830223, 0.10955369, 0.64215401, 0.23456345, 0.95944940,
|
||||
0.72822249, 0.40888451, 0.69980355, 0.26677428, 0.57333635, 0.39791582, 0.85377858, 0.76962816,
|
||||
0.72004885, 0.90903087, 0.51376506, 0.37732665, 0.12691640, 0.71249738, 0.81217908, 0.37037313,
|
||||
0.32772374, 0.14238259, 0.05614811, 0.74363008, 0.39773267, 0.94859135, 0.31452454, 0.11730313,
|
||||
0.62962618, 0.33334237, 0.45547255, 0.10089665, 0.56550662, 0.60539371, 0.16027624, 0.13245301,
|
||||
0.60959939, 0.04671662, 0.99356286, 0.57660859, 0.40269560, 0.45274629, 0.06699735, 0.85064246,
|
||||
0.87742744, 0.54508392, 0.87242982, 0.29321385, 0.67660627, 0.68230715, 0.79052073, 0.48592054,
|
||||
0.25186266, 0.93769755, 0.28565487, 0.47219067, 0.99054882, 0.13155240, 0.47110470, 0.98556600,
|
||||
0.84397623, 0.12875246, 0.90953202, 0.49129015, 0.23792727, 0.79481194, 0.44337770, 0.96564297,
|
||||
0.67749118, 0.55684872, 0.27286897, 0.79538393, 0.61965356, 0.22487929, 0.02226018, 0.49248200,
|
||||
0.42247006, 0.91797788, 0.99250134, 0.23449967, 0.52531508, 0.10246337, 0.78685622, 0.34310922,
|
||||
0.89892996, 0.40454552, 0.68608407, 0.30752487, 0.83601319, 0.54956031, 0.63777550, 0.82199797,
|
||||
0.24890696, 0.48801123, 0.48661910, 0.51223987, 0.32969635, 0.31075073, 0.21393155, 0.73453207,
|
||||
0.15565705, 0.58584522, 0.28976728, 0.97621478, 0.61498701, 0.23891470, 0.28518540, 0.46809591,
|
||||
0.18371914, 0.37597910, 0.13492176, 0.66849449, 0.82811466, 0.56240330, 0.37548956, 0.27562998,
|
||||
0.27521910, 0.74096121, 0.77176757, 0.13748143, 0.99747138, 0.92504502, 0.09175241, 0.21389176,
|
||||
0.21766512, 0.31183245, 0.23271221, 0.21207367, 0.57903312, 0.77523344, 0.13242613, 0.31037988,
|
||||
0.01204835, 0.71652949, 0.84487594, 0.14982178, 0.57423142, 0.45677888, 0.48420169, 0.53465428,
|
||||
0.52667473, 0.46880526, 0.49849733, 0.05670710, 0.79022476, 0.03872047, 0.21697212, 0.20443086,
|
||||
0.28949326, 0.81678186, 0.87629474, 0.92297064, 0.27373097, 0.84625273, 0.51505586, 0.00582792,
|
||||
0.33295971, 0.91848412, 0.92537226, 0.91760033, 0.07541125, 0.71745848, 0.61158698, 0.00941650,
|
||||
0.03135554, 0.71527471, 0.24821915, 0.63636652, 0.86159918, 0.26450229, 0.60160194, 0.35557725,
|
||||
0.24477500, 0.07186456, 0.51757096, 0.62120362, 0.97981062, 0.69954667, 0.21065616, 0.13382753,
|
||||
0.27693186, 0.59644095, 0.71500764, 0.04110751, 0.95730081, 0.91600724, 0.47704678, 0.26183479,
|
||||
0.34706971, 0.07545431, 0.29398385, 0.93236070, 0.60486023, 0.48015011, 0.08870451, 0.45548581,
|
||||
0.91872718, 0.38142712, 0.10668643, 0.01397541, 0.04520355, 0.93822273, 0.18011940, 0.57577277,
|
||||
0.91427606, 0.30911399, 0.95853475, 0.23611214, 0.69619891, 0.69601980, 0.76765372, 0.58515930,
|
||||
0.49479057, 0.11288752, 0.97187699, 0.32095365, 0.57563608, 0.40760618, 0.78703383, 0.43261152,
|
||||
0.90877651, 0.84686346, 0.10599030, 0.72872803, 0.19315490, 0.66152912, 0.10210518, 0.06257876,
|
||||
0.47950688, 0.47062066, 0.72701157, 0.48915116, 0.66110261, 0.60170685, 0.24516994, 0.12726050,
|
||||
0.03451185, 0.90864994, 0.83494878, 0.94800035, 0.91035206, 0.14480751, 0.88458997, 0.53498312,
|
||||
0.15963215, 0.55378627, 0.35171349, 0.28719791, 0.09097957, 0.00667896, 0.32309622, 0.87561479,
|
||||
0.42534520, 0.91748977, 0.73908457, 0.41793223, 0.99279792, 0.87908370, 0.28458072, 0.59132853,
|
||||
0.98672190, 0.28547393, 0.09452165, 0.89910674, 0.53681109, 0.37931425, 0.62683489, 0.56609740,
|
||||
0.24801549, 0.52948179, 0.98328855, 0.66403523, 0.55523786, 0.75886666, 0.84784685, 0.86829981,
|
||||
0.71448906, 0.84670080, 0.43922919, 0.20771016, 0.64157936, 0.25664246, 0.73055695, 0.86395782,
|
||||
0.65852932, 0.99061803, 0.40280575, 0.39146298, 0.07291005, 0.97200603, 0.20555729, 0.59616495,
|
||||
0.08138254, 0.45796388, 0.33681125, 0.33989127, 0.18717090, 0.53545811, 0.60550838, 0.86520709,
|
||||
0.34290701, 0.72743276, 0.73023855, 0.34195926, 0.65019733, 0.02765254, 0.72575740, 0.32709576,
|
||||
0.03420866, 0.26061893, 0.56997511, 0.28439072, 0.84422744, 0.77637570, 0.55982168, 0.06720327,
|
||||
0.58449067, 0.71657369, 0.15819609, 0.58042821, 0.07947911, 0.40193792, 0.11376012, 0.88762938,
|
||||
0.67532159, 0.71223735, 0.27829114, 0.04806073, 0.21144026, 0.58830274, 0.04140071, 0.43215628,
|
||||
0.12952729, 0.94668759, 0.87391019, 0.98382450, 0.27750768, 0.90849647, 0.90962737, 0.59269720,
|
||||
0.96102026, 0.49544979, 0.32007095, 0.62585546, 0.03119821, 0.85953001, 0.22017528, 0.05834068,
|
||||
0.80731217, 0.53799961, 0.74166948, 0.77426600, 0.43938444, 0.54862081, 0.58575513, 0.15886492,
|
||||
0.73214332, 0.11649057, 0.77463977, 0.85788827, 0.17061997, 0.66838056, 0.96076133, 0.07949296,
|
||||
0.68521946, 0.89986254, 0.05667410, 0.12741385, 0.83470977, 0.63969104, 0.46612929, 0.10200126,
|
||||
0.01194925, 0.10476340, 0.90285217, 0.31221221, 0.32980614, 0.46041971, 0.52024973, 0.05425470,
|
||||
0.28330912, 0.60426543, 0.00598243, 0.97244013, 0.21135841, 0.78561597, 0.78428734, 0.63422849,
|
||||
0.32909934, 0.44771136, 0.27380750, 0.14966697, 0.18156268, 0.65686758, 0.28726350, 0.97074787,
|
||||
0.63676171, 0.96649494, 0.24526295, 0.08297372, 0.54257548, 0.03166785, 0.33735355, 0.15946671,
|
||||
0.02102971, 0.46228045, 0.11892296, 0.33408336, 0.29875681, 0.29847692, 0.73767569, 0.02080745,
|
||||
0.62980060, 0.08082293, 0.22993106, 0.25031439, 0.87787525, 0.45150053, 0.13673441, 0.63407612,
|
||||
0.97907688, 0.52241942, 0.50580158, 0.06273902, 0.05270283, 0.77031811, 0.05113352, 0.24393329,
|
||||
0.75036441, 0.37436336, 0.22877652, 0.59975358, 0.85707591, 0.88691457, 0.85547165, 0.36641027,
|
||||
0.58720133, 0.45462835, 0.09243817, 0.32981586, 0.07820411, 0.25421519, 0.36004706, 0.60092307,
|
||||
0.46192412, 0.36758683, 0.98424170, 0.08019934, 0.68594024, 0.45826386, 0.29962317, 0.79365413,
|
||||
0.89231296, 0.49478547, 0.87645944, 0.23590734, 0.28106737, 0.75026285, 0.08136314, 0.79582424,
|
||||
0.76010628, 0.82792971, 0.27947652, 0.72482861, 0.82191216, 0.46171689, 0.79189752, 0.96043686,
|
||||
0.51609668, 0.88995725, 0.28998963, 0.55191845, 0.03934737, 0.83033700, 0.49553013, 0.98009549,
|
||||
0.19017594, 0.98347750, 0.33452066, 0.87144372, 0.72106301, 0.71272114, 0.71465963, 0.88361677,
|
||||
0.85571283, 0.73782329, 0.20920458, 0.34855153, 0.46766817, 0.02780062, 0.74898344, 0.03680650,
|
||||
0.44866557, 0.77426312, 0.91025891, 0.25195236, 0.87319953, 0.63265037, 0.25552148, 0.27422476,
|
||||
0.95217406, 0.39281839, 0.66441573, 0.09158900, 0.94515992, 0.07800798, 0.02507888, 0.39901462,
|
||||
0.17382573, 0.12141278, 0.85502334, 0.19902911, 0.02160210, 0.44460522, 0.14688742, 0.68020336,
|
||||
0.71323733, 0.60922473, 0.95400380, 0.99611159, 0.90897777, 0.41073520, 0.66206647, 0.32064685,
|
||||
0.62805003, 0.50677209, 0.52690101, 0.87473387, 0.73918362, 0.39826974, 0.43683919, 0.80459118,
|
||||
0.32422684, 0.01958019, 0.95319576, 0.98326137, 0.83931735, 0.69060863, 0.33671416, 0.68062550,
|
||||
0.65152380, 0.33392969, 0.03451730, 0.95227244, 0.68200635, 0.85074171, 0.64721009, 0.51234433,
|
||||
0.73402047, 0.00969637, 0.93835057, 0.80803854, 0.31485260, 0.20089527, 0.01323282, 0.59933780,
|
||||
0.31584602, 0.20209563, 0.33754800, 0.68604181, 0.24443049, 0.19952227, 0.78162632, 0.10336988,
|
||||
0.11360736, 0.23536740, 0.23262256, 0.67803776, 0.48749791, 0.74658435, 0.92156640, 0.56706407,
|
||||
0.36683221, 0.99157136, 0.23421374, 0.45183767, 0.91609720, 0.85573315, 0.37706276, 0.77042618,
|
||||
0.30891908, 0.40709595, 0.06944866, 0.61342849, 0.88817388, 0.58734506, 0.98711323, 0.14744128,
|
||||
0.63242656, 0.87704136, 0.68347125, 0.84446569, 0.43265239, 0.25146321, 0.04130111, 0.34259839,
|
||||
0.92697368, 0.40878778, 0.56990338, 0.76204273, 0.19820348, 0.66314909, 0.02482844, 0.06669207,
|
||||
0.50205581, 0.26084093, 0.65139159, 0.41650223, 0.09733904, 0.56344203, 0.62651696, 0.67332139,
|
||||
0.58037374, 0.47258086, 0.21010758, 0.05713135, 0.89390629, 0.10781246, 0.32037450, 0.07628388,
|
||||
0.34227964, 0.42190597, 0.58201860, 0.77363549, 0.49595133, 0.86031236, 0.83906769, 0.81098161,
|
||||
0.26694195, 0.14215941, 0.88210306, 0.53634237, 0.12090720, 0.82480459, 0.75930318, 0.31847147,
|
||||
0.92768077, 0.01037616, 0.56201727, 0.88107122, 0.35925856, 0.85860762, 0.61109408, 0.70408301,
|
||||
0.58434977, 0.92192494, 0.62667915, 0.75988365, 0.06858761, 0.36156496, 0.58057195, 0.13636150,
|
||||
0.57719713, 0.59340255, 0.63530602, 0.22976282, 0.71915530, 0.41162531, 0.63979565, 0.09931342,
|
||||
0.79344045, 0.10893790, 0.84450224, 0.23122236, 0.99485593, 0.73637397, 0.17276368, 0.13357764,
|
||||
0.74965804, 0.64991737, 0.61990341, 0.41523170, 0.05878239, 0.05687301, 0.05497131, 0.42868366,
|
||||
0.42571090, 0.25810502, 0.89642955, 0.30439758, 0.39310223, 0.11357431, 0.04288255, 0.23397550,
|
||||
0.11200634, 0.85621396, 0.89733974, 0.37508865, 0.42077265, 0.68597384, 0.72781399, 0.19296476,
|
||||
0.61699087, 0.31667128, 0.67756410, 0.00177323, 0.05725176, 0.79474693, 0.18885238, 0.06724856,
|
||||
0.68193156, 0.42202167, 0.22082041, 0.28554673, 0.64995708, 0.87851940, 0.29124547, 0.61009521,
|
||||
0.87374537, 0.05743712, 0.69902994, 0.81925115, 0.45653873, 0.37236821, 0.31118709, 0.52734307,
|
||||
0.39672836, 0.38185294, 0.30163915, 0.17374510, 0.04913278, 0.90404879, 0.25742801, 0.58266467,
|
||||
0.97663209, 0.79823377, 0.36437958, 0.15206043, 0.26529938, 0.22690047, 0.05839021, 0.84721160,
|
||||
0.18622435, 0.37809403, 0.55706977, 0.49828704, 0.47659049, 0.24289680, 0.88477595, 0.07807463,
|
||||
0.56245739, 0.73490635, 0.21099431, 0.13164942, 0.75840044, 0.66877037, 0.28988183, 0.44046090,
|
||||
0.24967434, 0.80048356, 0.26029740, 0.30416821, 0.64151867, 0.52067892, 0.12880774, 0.85465381,
|
||||
0.02690525, 0.19149288, 0.49630295, 0.79682619, 0.43566145, 0.00288078, 0.81484193, 0.03763639,
|
||||
0.68529083, 0.01339574, 0.38405386, 0.30537067, 0.22994703, 0.44000045, 0.27217985, 0.53831243,
|
||||
0.02870435, 0.86282045, 0.61831306, 0.09164956, 0.25609707, 0.07445781, 0.72185784, 0.90058883,
|
||||
0.30070608, 0.94476583, 0.56822213, 0.21933909, 0.96772793, 0.80063440, 0.26307906, 0.31183306,
|
||||
0.16501252, 0.55436179, 0.68562285, 0.23829083, 0.86511559, 0.57868991, 0.81888344, 0.20126869,
|
||||
0.93172350, 0.66028129, 0.21786948, 0.78515828, 0.10262106, 0.35390326, 0.79303876, 0.63427924,
|
||||
0.90479631, 0.31024934, 0.60635447, 0.56198079, 0.63573813, 0.91854197, 0.99701497, 0.83085849,
|
||||
0.31692291, 0.01925964, 0.97446405, 0.98751283, 0.60944293, 0.13751018, 0.69519957, 0.68956636,
|
||||
0.56969015, 0.46440193, 0.88341765, 0.36754434, 0.89223647, 0.39786427, 0.85055280, 0.12749961,
|
||||
0.79452122, 0.89449784, 0.14567830, 0.45716830, 0.74822309, 0.28200437, 0.42546044, 0.17464886,
|
||||
0.68308746, 0.65496587, 0.52935411, 0.12736159, 0.61523955, 0.81590528, 0.63107864, 0.39786553,
|
||||
0.20102294, 0.53292914, 0.75485590, 0.59847044, 0.32861691, 0.12125866, 0.58917183, 0.07638293,
|
||||
0.86845380, 0.29192617, 0.03989733, 0.52180460, 0.32503407, 0.64071852, 0.69516575, 0.74254998,
|
||||
0.54587026, 0.48713246, 0.32920155, 0.08719954, 0.63497059, 0.54328459, 0.64178757, 0.45583809,
|
||||
0.70694291, 0.85212760, 0.86074305, 0.33163422, 0.85739792, 0.59908488, 0.74566046, 0.72157152
|
||||
};
|
||||
|
||||
for (int i = 0; i < refInt.length; ++i) {
|
||||
int r = mt.nextInt();
|
||||
Assert.assertEquals(refInt[i], (r & 0x7fffffffl) | ((r < 0) ? 0x80000000l : 0x0l));
|
||||
}
|
||||
|
||||
for (int i = 0; i < refDouble.length; ++i) {
|
||||
int r = mt.nextInt();
|
||||
Assert.assertEquals(refDouble[i],
|
||||
((r & 0x7fffffffl) | ((r < 0) ? 0x80000000l : 0x0l)) / 4294967296.0,
|
||||
1.0e-8);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,126 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.commons.math4.random.RandomAdaptor;
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test cases for the RandomAdaptor class
|
||||
*
|
||||
*/
|
||||
|
||||
public class RandomAdaptorTest {
|
||||
|
||||
@Test
|
||||
public void testAdaptor() {
|
||||
ConstantGenerator generator = new ConstantGenerator();
|
||||
Random random = RandomAdaptor.createAdaptor(generator);
|
||||
checkConstant(random);
|
||||
RandomAdaptor randomAdaptor = new RandomAdaptor(generator);
|
||||
checkConstant(randomAdaptor);
|
||||
}
|
||||
|
||||
private void checkConstant(Random random) {
|
||||
byte[] bytes = new byte[] {0};
|
||||
random.nextBytes(bytes);
|
||||
Assert.assertEquals(0, bytes[0]);
|
||||
Assert.assertFalse(random.nextBoolean());
|
||||
Assert.assertEquals(0, random.nextDouble(), 0);
|
||||
Assert.assertEquals(0, random.nextFloat(), 0);
|
||||
Assert.assertEquals(0, random.nextGaussian(), 0);
|
||||
Assert.assertEquals(0, random.nextInt());
|
||||
Assert.assertEquals(0, random.nextInt(1));
|
||||
Assert.assertEquals(0, random.nextLong());
|
||||
random.setSeed(100);
|
||||
Assert.assertEquals(0, random.nextDouble(), 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* "Constant" generator to test Adaptor delegation.
|
||||
* "Powered by Eclipse ;-)"
|
||||
*
|
||||
*/
|
||||
public static class ConstantGenerator implements RandomGenerator {
|
||||
|
||||
private final double value;
|
||||
|
||||
public ConstantGenerator() {
|
||||
value = 0;
|
||||
}
|
||||
|
||||
public ConstantGenerator(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean nextBoolean() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nextBytes(byte[] bytes) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public double nextDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float nextFloat() {
|
||||
return (float) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double nextGaussian() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextInt() {
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextInt(int n) {
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long nextLong() {
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSeed(int seed) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSeed(int[] seed) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSeed(long seed) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,462 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.commons.math4.TestUtils;
|
||||
import org.apache.commons.math4.distribution.RealDistribution;
|
||||
import org.apache.commons.math4.distribution.UniformRealDistribution;
|
||||
import org.apache.commons.math4.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math4.stat.Frequency;
|
||||
import org.apache.commons.math4.stat.inference.KolmogorovSmirnovTest;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Base class for RandomGenerator tests.
|
||||
*
|
||||
* Tests RandomGenerator methods directly and also executes RandomDataTest
|
||||
* test cases against a RandomDataImpl created using the provided generator.
|
||||
*
|
||||
* RandomGenerator test classes should extend this class, implementing
|
||||
* makeGenerator() to provide a concrete generator to test. The generator
|
||||
* returned by makeGenerator should be seeded with a fixed seed.
|
||||
*
|
||||
*/
|
||||
|
||||
public abstract class RandomGeneratorAbstractTest extends RandomDataGeneratorTest {
|
||||
|
||||
/** RandomGenerator under test */
|
||||
protected RandomGenerator generator;
|
||||
|
||||
/**
|
||||
* Override this method in subclasses to provide a concrete generator to test.
|
||||
* Return a generator seeded with a fixed seed.
|
||||
*/
|
||||
protected abstract RandomGenerator makeGenerator();
|
||||
|
||||
/**
|
||||
* Initialize generator and randomData instance in superclass.
|
||||
*/
|
||||
public RandomGeneratorAbstractTest() {
|
||||
generator = makeGenerator();
|
||||
randomData = new RandomDataGenerator(generator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a fixed seed for the tests
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
generator = makeGenerator();
|
||||
}
|
||||
|
||||
// Omit secureXxx tests, since they do not use the provided generator
|
||||
@Override
|
||||
public void testNextSecureLongIAE() {}
|
||||
@Override
|
||||
public void testNextSecureLongNegativeToPositiveRange() {}
|
||||
@Override
|
||||
public void testNextSecureLongNegativeRange() {}
|
||||
@Override
|
||||
public void testNextSecureLongPositiveRange() {}
|
||||
@Override
|
||||
public void testNextSecureIntIAE() {}
|
||||
@Override
|
||||
public void testNextSecureIntNegativeToPositiveRange() {}
|
||||
@Override
|
||||
public void testNextSecureIntNegativeRange() {}
|
||||
@Override
|
||||
public void testNextSecureIntPositiveRange() {}
|
||||
@Override
|
||||
public void testNextSecureHex() {}
|
||||
|
||||
@Test
|
||||
/**
|
||||
* Tests uniformity of nextInt(int) distribution by generating 1000
|
||||
* samples for each of 10 test values and for each sample performing
|
||||
* a chi-square test of homogeneity of the observed distribution with
|
||||
* the expected uniform distribution. Tests are performed at the .01
|
||||
* level and an average failure rate higher than 2% (i.e. more than 20
|
||||
* null hypothesis rejections) causes the test case to fail.
|
||||
*
|
||||
* All random values are generated using the generator instance used by
|
||||
* other tests and the generator is not reseeded, so this is a fixed seed
|
||||
* test.
|
||||
*/
|
||||
public void testNextIntDirect() {
|
||||
// Set up test values - end of the array filled randomly
|
||||
int[] testValues = new int[] {4, 10, 12, 32, 100, 10000, 0, 0, 0, 0};
|
||||
for (int i = 6; i < 10; i++) {
|
||||
final int val = generator.nextInt();
|
||||
testValues[i] = val < 0 ? -val : val + 1;
|
||||
}
|
||||
|
||||
final int numTests = 1000;
|
||||
for (int i = 0; i < testValues.length; i++) {
|
||||
final int n = testValues[i];
|
||||
// Set up bins
|
||||
int[] binUpperBounds;
|
||||
if (n < 32) {
|
||||
binUpperBounds = new int[n];
|
||||
for (int k = 0; k < n; k++) {
|
||||
binUpperBounds[k] = k;
|
||||
}
|
||||
} else {
|
||||
binUpperBounds = new int[10];
|
||||
final int step = n / 10;
|
||||
for (int k = 0; k < 9; k++) {
|
||||
binUpperBounds[k] = (k + 1) * step;
|
||||
}
|
||||
binUpperBounds[9] = n - 1;
|
||||
}
|
||||
// Run the tests
|
||||
int numFailures = 0;
|
||||
final int binCount = binUpperBounds.length;
|
||||
final long[] observed = new long[binCount];
|
||||
final double[] expected = new double[binCount];
|
||||
expected[0] = binUpperBounds[0] == 0 ? (double) smallSampleSize / (double) n :
|
||||
(double) ((binUpperBounds[0] + 1) * smallSampleSize) / (double) n;
|
||||
for (int k = 1; k < binCount; k++) {
|
||||
expected[k] = (double) smallSampleSize *
|
||||
(double) (binUpperBounds[k] - binUpperBounds[k - 1]) / n;
|
||||
}
|
||||
for (int j = 0; j < numTests; j++) {
|
||||
Arrays.fill(observed, 0);
|
||||
for (int k = 0; k < smallSampleSize; k++) {
|
||||
final int value = generator.nextInt(n);
|
||||
Assert.assertTrue("nextInt range",(value >= 0) && (value < n));
|
||||
for (int l = 0; l < binCount; l++) {
|
||||
if (binUpperBounds[l] >= value) {
|
||||
observed[l]++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (testStatistic.chiSquareTest(expected, observed) < 0.01) {
|
||||
numFailures++;
|
||||
}
|
||||
}
|
||||
if ((double) numFailures / (double) numTests > 0.02) {
|
||||
Assert.fail("Too many failures for n = " + n +
|
||||
" " + numFailures + " out of " + numTests + " tests failed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNextLongDirect() {
|
||||
long q1 = Long.MAX_VALUE/4;
|
||||
long q2 = 2 * q1;
|
||||
long q3 = 3 * q1;
|
||||
|
||||
Frequency freq = new Frequency();
|
||||
long val = 0;
|
||||
int value = 0;
|
||||
for (int i=0; i<smallSampleSize; i++) {
|
||||
val = generator.nextLong();
|
||||
val = val < 0 ? -val : val;
|
||||
if (val < q1) {
|
||||
value = 0;
|
||||
} else if (val < q2) {
|
||||
value = 1;
|
||||
} else if (val < q3) {
|
||||
value = 2;
|
||||
} else {
|
||||
value = 3;
|
||||
}
|
||||
freq.addValue(value);
|
||||
}
|
||||
long[] observed = new long[4];
|
||||
for (int i=0; i<4; i++) {
|
||||
observed[i] = freq.getCount(i);
|
||||
}
|
||||
|
||||
/* Use ChiSquare dist with df = 4-1 = 3, alpha = .001
|
||||
* Change to 11.34 for alpha = .01
|
||||
*/
|
||||
Assert.assertTrue("chi-square test -- will fail about 1 in 1000 times",
|
||||
testStatistic.chiSquare(expected,observed) < 16.27);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNextBooleanDirect() {
|
||||
long halfSampleSize = smallSampleSize / 2;
|
||||
double[] expected = {halfSampleSize, halfSampleSize};
|
||||
long[] observed = new long[2];
|
||||
for (int i=0; i<smallSampleSize; i++) {
|
||||
if (generator.nextBoolean()) {
|
||||
observed[0]++;
|
||||
} else {
|
||||
observed[1]++;
|
||||
}
|
||||
}
|
||||
/* Use ChiSquare dist with df = 2-1 = 1, alpha = .001
|
||||
* Change to 6.635 for alpha = .01
|
||||
*/
|
||||
Assert.assertTrue("chi-square test -- will fail about 1 in 1000 times",
|
||||
testStatistic.chiSquare(expected,observed) < 10.828);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNextFloatDirect() {
|
||||
Frequency freq = new Frequency();
|
||||
float val = 0;
|
||||
int value = 0;
|
||||
for (int i=0; i<smallSampleSize; i++) {
|
||||
val = generator.nextFloat();
|
||||
if (val < 0.25) {
|
||||
value = 0;
|
||||
} else if (val < 0.5) {
|
||||
value = 1;
|
||||
} else if (val < 0.75) {
|
||||
value = 2;
|
||||
} else {
|
||||
value = 3;
|
||||
}
|
||||
freq.addValue(value);
|
||||
}
|
||||
long[] observed = new long[4];
|
||||
for (int i=0; i<4; i++) {
|
||||
observed[i] = freq.getCount(i);
|
||||
}
|
||||
|
||||
/* Use ChiSquare dist with df = 4-1 = 3, alpha = .001
|
||||
* Change to 11.34 for alpha = .01
|
||||
*/
|
||||
Assert.assertTrue("chi-square test -- will fail about 1 in 1000 times",
|
||||
testStatistic.chiSquare(expected,observed) < 16.27);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNextDouble() {
|
||||
final double[] sample = new double[1000];
|
||||
for (int i = 0; i < sample.length; i++) {
|
||||
sample[i] = generator.nextDouble();
|
||||
}
|
||||
final RealDistribution uniformDistribution = new UniformRealDistribution(0,1);
|
||||
final KolmogorovSmirnovTest ks = new KolmogorovSmirnovTest();
|
||||
Assert.assertFalse(ks.kolmogorovSmirnovTest(uniformDistribution, sample, .01));
|
||||
}
|
||||
|
||||
|
||||
@Test(expected=MathIllegalArgumentException.class)
|
||||
public void testNextIntPrecondition1() {
|
||||
generator.nextInt(-1);
|
||||
}
|
||||
|
||||
@Test(expected=MathIllegalArgumentException.class)
|
||||
public void testNextIntPrecondition2() {
|
||||
generator.nextInt(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNextInt2() {
|
||||
int walk = 0;
|
||||
final int N = 10000;
|
||||
for (int k = 0; k < N; ++k) {
|
||||
if (generator.nextInt() >= 0) {
|
||||
++walk;
|
||||
} else {
|
||||
--walk;
|
||||
}
|
||||
}
|
||||
Assert.assertTrue("Walked too far astray: " + walk + "\nNote: This " +
|
||||
"test will fail randomly about 1 in 100 times.",
|
||||
FastMath.abs(walk) < FastMath.sqrt(N) * 2.576);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNextLong2() {
|
||||
int walk = 0;
|
||||
final int N = 1000;
|
||||
for (int k = 0; k < N; ++k) {
|
||||
if (generator.nextLong() >= 0) {
|
||||
++walk;
|
||||
} else {
|
||||
--walk;
|
||||
}
|
||||
}
|
||||
Assert.assertTrue("Walked too far astray: " + walk + "\nNote: This " +
|
||||
"test will fail randomly about 1 in 100 times.",
|
||||
FastMath.abs(walk) < FastMath.sqrt(N) * 2.576);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNextBoolean2() {
|
||||
int walk = 0;
|
||||
final int N = 10000;
|
||||
for (int k = 0; k < N; ++k) {
|
||||
if (generator.nextBoolean()) {
|
||||
++walk;
|
||||
} else {
|
||||
--walk;
|
||||
}
|
||||
}
|
||||
Assert.assertTrue("Walked too far astray: " + walk + "\nNote: This " +
|
||||
"test will fail randomly about 1 in 100 times.",
|
||||
FastMath.abs(walk) < FastMath.sqrt(N) * 2.576);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNextBytes() {
|
||||
long[] count = new long[256];
|
||||
byte[] bytes = new byte[10];
|
||||
double[] expected = new double[256];
|
||||
final int sampleSize = 100000;
|
||||
|
||||
for (int i = 0; i < 256; i++) {
|
||||
expected[i] = (double) sampleSize / 265f;
|
||||
}
|
||||
|
||||
for (int k = 0; k < sampleSize; ++k) {
|
||||
generator.nextBytes(bytes);
|
||||
for (byte b : bytes) {
|
||||
++count[b + 128];
|
||||
}
|
||||
}
|
||||
|
||||
TestUtils.assertChiSquareAccept(expected, count, 0.001);
|
||||
|
||||
}
|
||||
|
||||
// MATH-1300
|
||||
@Test
|
||||
public void testNextBytesChunks() {
|
||||
final int[] chunkSizes = { 4, 8, 12, 16 };
|
||||
final int[] chunks = { 1, 2, 3, 4, 5 };
|
||||
for (int chunkSize : chunkSizes) {
|
||||
for (int numChunks : chunks) {
|
||||
checkNextBytesChunks(chunkSize, numChunks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MATH-1300: Test is ignored because it will fail due to the array
|
||||
// size not being a multiple of 4.
|
||||
@Ignore@Test
|
||||
public void testNextBytesChunksFail() {
|
||||
final int[] chunkSizes = { 5 };
|
||||
final int[] chunks = { 4 };
|
||||
for (int chunkSize : chunkSizes) {
|
||||
for (int numChunks : chunks) {
|
||||
checkNextBytesChunks(chunkSize, numChunks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSeeding() {
|
||||
// makeGenerator initializes with fixed seed
|
||||
RandomGenerator gen = makeGenerator();
|
||||
RandomGenerator gen1 = makeGenerator();
|
||||
checkSameSequence(gen, gen1);
|
||||
// reseed, but recreate the second one
|
||||
// verifies MATH-723
|
||||
gen.setSeed(100);
|
||||
gen1 = makeGenerator();
|
||||
gen1.setSeed(100);
|
||||
checkSameSequence(gen, gen1);
|
||||
}
|
||||
|
||||
private void checkSameSequence(RandomGenerator gen1, RandomGenerator gen2) {
|
||||
final int len = 11; // Needs to be an odd number to check MATH-723
|
||||
final double[][] values = new double[2][len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
values[0][i] = gen1.nextDouble();
|
||||
}
|
||||
for (int i = 0; i < len; i++) {
|
||||
values[1][i] = gen2.nextDouble();
|
||||
}
|
||||
Assert.assertTrue(Arrays.equals(values[0], values[1]));
|
||||
for (int i = 0; i < len; i++) {
|
||||
values[0][i] = gen1.nextFloat();
|
||||
}
|
||||
for (int i = 0; i < len; i++) {
|
||||
values[1][i] = gen2.nextFloat();
|
||||
}
|
||||
Assert.assertTrue(Arrays.equals(values[0], values[1]));
|
||||
for (int i = 0; i < len; i++) {
|
||||
values[0][i] = gen1.nextInt();
|
||||
}
|
||||
for (int i = 0; i < len; i++) {
|
||||
values[1][i] = gen2.nextInt();
|
||||
}
|
||||
Assert.assertTrue(Arrays.equals(values[0], values[1]));
|
||||
for (int i = 0; i < len; i++) {
|
||||
values[0][i] = gen1.nextLong();
|
||||
}
|
||||
for (int i = 0; i < len; i++) {
|
||||
values[1][i] = gen2.nextLong();
|
||||
}
|
||||
Assert.assertTrue(Arrays.equals(values[0], values[1]));
|
||||
for (int i = 0; i < len; i++) {
|
||||
values[0][i] = gen1.nextInt(len);
|
||||
}
|
||||
for (int i = 0; i < len; i++) {
|
||||
values[1][i] = gen2.nextInt(len);
|
||||
}
|
||||
Assert.assertTrue(Arrays.equals(values[0], values[1]));
|
||||
for (int i = 0; i < len; i++) {
|
||||
values[0][i] = gen1.nextBoolean() ? 1 : 0;
|
||||
}
|
||||
for (int i = 0; i < len; i++) {
|
||||
values[1][i] = gen2.nextBoolean() ? 1 : 0;
|
||||
}
|
||||
Assert.assertTrue(Arrays.equals(values[0], values[1]));
|
||||
for (int i = 0; i < len; i++) {
|
||||
values[0][i] = gen1.nextGaussian();
|
||||
}
|
||||
for (int i = 0; i < len; i++) {
|
||||
values[1][i] = gen2.nextGaussian();
|
||||
}
|
||||
Assert.assertTrue(Arrays.equals(values[0], values[1]));
|
||||
}
|
||||
|
||||
// MATH-1300
|
||||
private void checkNextBytesChunks(int chunkSize,
|
||||
int numChunks) {
|
||||
final RandomGenerator rg = makeGenerator();
|
||||
final long seed = 1234567L;
|
||||
|
||||
final byte[] b1 = new byte[chunkSize * numChunks];
|
||||
final byte[] b2 = new byte[chunkSize];
|
||||
|
||||
// Generate the chunks in a single call.
|
||||
rg.setSeed(seed);
|
||||
rg.nextBytes(b1);
|
||||
|
||||
// Reset.
|
||||
rg.setSeed(seed);
|
||||
// Generate the chunks in consecutive calls.
|
||||
for (int i = 0; i < numChunks; i++) {
|
||||
rg.nextBytes(b2);
|
||||
}
|
||||
|
||||
// Store last 128 bytes chunk of b1 into b3.
|
||||
final byte[] b3 = new byte[chunkSize];
|
||||
System.arraycopy(b1, b1.length - b3.length, b3, 0, b3.length);
|
||||
|
||||
// Sequence of calls must be the same.
|
||||
Assert.assertArrayEquals("chunkSize=" + chunkSize + " numChunks=" + numChunks,
|
||||
b2, b3);
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.apache.commons.math4.random.RandomGeneratorFactory;
|
||||
|
||||
/**
|
||||
* Test cases for the {@link RandomGeneratorFactory} class.
|
||||
*
|
||||
*/
|
||||
public class RandomGeneratorFactoryTest extends RandomGeneratorAbstractTest {
|
||||
|
||||
@Override
|
||||
protected RandomGenerator makeGenerator() {
|
||||
RandomGenerator generator = RandomGeneratorFactory.createRandomGenerator(new Random());
|
||||
generator.setSeed(1001);
|
||||
return generator;
|
||||
}
|
||||
}
|
|
@ -24,9 +24,7 @@ import java.util.concurrent.ExecutorService;
|
|||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.apache.commons.math4.random.MersenneTwister;
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.apache.commons.math4.random.SynchronizedRandomGenerator;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -38,9 +36,9 @@ public class SynchronizedRandomGeneratorTest {
|
|||
@Test
|
||||
public void testAdapter() {
|
||||
final int seed = 12345;
|
||||
final RandomGenerator orig = new MersenneTwister(seed);
|
||||
final RandomGenerator orig = new RngAdaptor(RandomSource.MT, seed);
|
||||
final RandomGenerator wrap
|
||||
= new SynchronizedRandomGenerator(new MersenneTwister(seed));
|
||||
= new SynchronizedRandomGenerator(new RngAdaptor(RandomSource.MT, seed));
|
||||
|
||||
final int bSize = 67;
|
||||
final byte[] bOrig = new byte[bSize];
|
||||
|
@ -92,7 +90,7 @@ public class SynchronizedRandomGeneratorTest {
|
|||
final int numSamples)
|
||||
throws InterruptedException,
|
||||
ExecutionException {
|
||||
final RandomGenerator rng = new MersenneTwister();
|
||||
final RandomGenerator rng = new RngAdaptor(RandomSource.MT);
|
||||
final RandomGenerator wrapper = sync ? new SynchronizedRandomGenerator(rng) : rng;
|
||||
|
||||
final List<Callable<Double>> tasks = new ArrayList<Callable<Double>>();
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.commons.math4.random.AbstractRandomGenerator;
|
||||
|
||||
/**
|
||||
* Dummy AbstractRandomGenerator concrete subclass that just wraps a
|
||||
* java.util.Random instance. Used by AbstractRandomGeneratorTest to test
|
||||
* default implementations in AbstractRandomGenerator.
|
||||
*
|
||||
*/
|
||||
public class TestRandomGenerator extends AbstractRandomGenerator {
|
||||
|
||||
private Random random = new Random();
|
||||
|
||||
@Override
|
||||
public void setSeed(long seed) {
|
||||
clear();
|
||||
random.setSeed(seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double nextDouble() {
|
||||
return random.nextDouble();
|
||||
}
|
||||
|
||||
}
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import org.apache.commons.math4.random.JDKRandomGenerator;
|
||||
import org.apache.commons.math4.rng.UniformRandomProvider;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
import org.apache.commons.math4.stat.StatUtils;
|
||||
|
|
|
@ -1,242 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.commons.math4.RetryRunner;
|
||||
import org.apache.commons.math4.exception.MathIllegalStateException;
|
||||
import org.apache.commons.math4.exception.ZeroException;
|
||||
import org.apache.commons.math4.random.ValueServer;
|
||||
import org.apache.commons.math4.random.Well19937c;
|
||||
import org.apache.commons.math4.stat.descriptive.SummaryStatistics;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* Test cases for the ValueServer class.
|
||||
*
|
||||
*/
|
||||
|
||||
@RunWith(RetryRunner.class)
|
||||
public final class ValueServerTest {
|
||||
|
||||
private final ValueServer vs = new ValueServer(new Well19937c(100));
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
vs.setMode(ValueServer.DIGEST_MODE);
|
||||
URL url = getClass().getResource("testData.txt");
|
||||
vs.setValuesFileURL(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate 1000 random values and make sure they look OK.<br>
|
||||
* Note that there is a non-zero (but very small) probability that
|
||||
* these tests will fail even if the code is working as designed.
|
||||
*/
|
||||
@Test
|
||||
public void testNextDigest() throws Exception {
|
||||
double next = 0.0;
|
||||
double tolerance = 0.1;
|
||||
vs.computeDistribution();
|
||||
Assert.assertTrue("empirical distribution property",
|
||||
vs.getEmpiricalDistribution() != null);
|
||||
SummaryStatistics stats = new SummaryStatistics();
|
||||
for (int i = 1; i < 1000; i++) {
|
||||
next = vs.getNext();
|
||||
stats.addValue(next);
|
||||
}
|
||||
Assert.assertEquals("mean", 5.069831575018909, stats.getMean(), tolerance);
|
||||
Assert.assertEquals("std dev", 1.0173699343977738, stats.getStandardDeviation(),
|
||||
tolerance);
|
||||
|
||||
vs.computeDistribution(500);
|
||||
stats = new SummaryStatistics();
|
||||
for (int i = 1; i < 1000; i++) {
|
||||
next = vs.getNext();
|
||||
stats.addValue(next);
|
||||
}
|
||||
Assert.assertEquals("mean", 5.069831575018909, stats.getMean(), tolerance);
|
||||
Assert.assertEquals("std dev", 1.0173699343977738, stats.getStandardDeviation(),
|
||||
tolerance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that when provided with fixed seeds, stochastic modes
|
||||
* generate fixed sequences. Verifies the fix for MATH-654.
|
||||
*/
|
||||
@Test
|
||||
public void testFixedSeed() throws Exception {
|
||||
ValueServer valueServer = new ValueServer();
|
||||
URL url = getClass().getResource("testData.txt");
|
||||
valueServer.setValuesFileURL(url);
|
||||
valueServer.computeDistribution();
|
||||
checkFixedSeed(valueServer, ValueServer.DIGEST_MODE);
|
||||
checkFixedSeed(valueServer, ValueServer.EXPONENTIAL_MODE);
|
||||
checkFixedSeed(valueServer, ValueServer.GAUSSIAN_MODE);
|
||||
checkFixedSeed(valueServer, ValueServer.UNIFORM_MODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the check for {@link #testFixedSeed()}
|
||||
* @param mode ValueServer mode
|
||||
*/
|
||||
private void checkFixedSeed(ValueServer valueServer, int mode) throws Exception {
|
||||
valueServer.reSeed(1000);
|
||||
valueServer.setMode(mode);
|
||||
double[][] values = new double[2][100];
|
||||
for (int i = 0; i < 100; i++) {
|
||||
values[0][i] = valueServer.getNext();
|
||||
}
|
||||
valueServer.reSeed(1000);
|
||||
for (int i = 0; i < 100; i++) {
|
||||
values[1][i] = valueServer.getNext();
|
||||
}
|
||||
Assert.assertTrue(Arrays.equals(values[0], values[1]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure exception thrown if digest getNext is attempted
|
||||
* before loading empiricalDistribution.
|
||||
*/
|
||||
@Test
|
||||
public void testNextDigestFail() throws Exception {
|
||||
try {
|
||||
vs.getNext();
|
||||
Assert.fail("Expecting MathIllegalStateException");
|
||||
} catch (MathIllegalStateException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyReplayFile() throws Exception {
|
||||
try {
|
||||
URL url = getClass().getResource("emptyFile.txt");
|
||||
vs.setMode(ValueServer.REPLAY_MODE);
|
||||
vs.setValuesFileURL(url);
|
||||
vs.getNext();
|
||||
Assert.fail("an exception should have been thrown");
|
||||
} catch (MathIllegalStateException mise) {
|
||||
// expected behavior
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyDigestFile() throws Exception {
|
||||
try {
|
||||
URL url = getClass().getResource("emptyFile.txt");
|
||||
vs.setMode(ValueServer.DIGEST_MODE);
|
||||
vs.setValuesFileURL(url);
|
||||
vs.computeDistribution();
|
||||
Assert.fail("an exception should have been thrown");
|
||||
} catch (ZeroException ze) {
|
||||
// expected behavior
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test ValueServer REPLAY_MODE using values in testData file.<br>
|
||||
* Check that the values 1,2,1001,1002 match data file values 1 and 2.
|
||||
* the sample data file.
|
||||
*/
|
||||
@Test
|
||||
public void testReplay() throws Exception {
|
||||
double firstDataValue = 4.038625496201205;
|
||||
double secondDataValue = 3.6485326248346936;
|
||||
double tolerance = 10E-15;
|
||||
double compareValue = 0.0d;
|
||||
vs.setMode(ValueServer.REPLAY_MODE);
|
||||
vs.resetReplayFile();
|
||||
compareValue = vs.getNext();
|
||||
Assert.assertEquals(compareValue,firstDataValue,tolerance);
|
||||
compareValue = vs.getNext();
|
||||
Assert.assertEquals(compareValue,secondDataValue,tolerance);
|
||||
for (int i = 3; i < 1001; i++) {
|
||||
compareValue = vs.getNext();
|
||||
}
|
||||
compareValue = vs.getNext();
|
||||
Assert.assertEquals(compareValue,firstDataValue,tolerance);
|
||||
compareValue = vs.getNext();
|
||||
Assert.assertEquals(compareValue,secondDataValue,tolerance);
|
||||
vs.closeReplayFile();
|
||||
// make sure no NPE
|
||||
vs.closeReplayFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test other ValueServer modes
|
||||
*/
|
||||
@Test
|
||||
public void testModes() throws Exception {
|
||||
vs.setMode(ValueServer.CONSTANT_MODE);
|
||||
vs.setMu(0);
|
||||
Assert.assertEquals("constant mode test",vs.getMu(),vs.getNext(),Double.MIN_VALUE);
|
||||
vs.setMode(ValueServer.UNIFORM_MODE);
|
||||
vs.setMu(2);
|
||||
double val = vs.getNext();
|
||||
Assert.assertTrue(val > 0 && val < 4);
|
||||
vs.setSigma(1);
|
||||
vs.setMode(ValueServer.GAUSSIAN_MODE);
|
||||
val = vs.getNext();
|
||||
Assert.assertTrue("gaussian value close enough to mean",
|
||||
val < vs.getMu() + 100*vs.getSigma());
|
||||
vs.setMode(ValueServer.EXPONENTIAL_MODE);
|
||||
val = vs.getNext();
|
||||
Assert.assertTrue(val > 0);
|
||||
try {
|
||||
vs.setMode(1000);
|
||||
vs.getNext();
|
||||
Assert.fail("bad mode, expecting MathIllegalStateException");
|
||||
} catch (MathIllegalStateException ex) {
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test fill
|
||||
*/
|
||||
@Test
|
||||
public void testFill() throws Exception {
|
||||
vs.setMode(ValueServer.CONSTANT_MODE);
|
||||
vs.setMu(2);
|
||||
double[] val = new double[5];
|
||||
vs.fill(val);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Assert.assertEquals("fill test in place",2,val[i],Double.MIN_VALUE);
|
||||
}
|
||||
double v2[] = vs.fill(3);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Assert.assertEquals("fill test in place",2,v2[i],Double.MIN_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getters to make Clover happy
|
||||
*/
|
||||
@Test
|
||||
public void testProperties() throws Exception {
|
||||
vs.setMode(ValueServer.CONSTANT_MODE);
|
||||
Assert.assertEquals("mode test",ValueServer.CONSTANT_MODE,vs.getMode());
|
||||
vs.setValuesFileURL("http://www.apache.org");
|
||||
URL url = vs.getValuesFileURL();
|
||||
Assert.assertEquals("valuesFileURL test","http://www.apache.org",url.toString());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.apache.commons.math4.random.Well1024a;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Well1024aTest extends RandomGeneratorAbstractTest {
|
||||
|
||||
@Override
|
||||
protected RandomGenerator makeGenerator() {
|
||||
return new Well1024a(1001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReferenceCode() {
|
||||
Well1024a mt = new Well1024a(new int[] {
|
||||
740849862, 1202665156, -199039369, -259008301, -291878969, -1164428990, -1565918811, 491009864,
|
||||
-1883086670, 1383450241, 1244617256, 689006653, -1576746370, -1307940314, 1421489086, 1742094000,
|
||||
-595495729, 1047766204, 1875773301, -1637793284, 1379017098, 262792705, 191880010, -251000180,
|
||||
-1753047622, -972355720, 90626881, 1644693418, 1503365577, 439653419, 1806361562, 1268823869
|
||||
});
|
||||
int[] refInt = {
|
||||
-1478749726, -1645579484, -2075363835, -2063444174, -1834148336, -1769045872, -40711346, 1717441026,
|
||||
2130656771, 783441285, 570433609, 1560023451, 653233971, 1368672434, -72036215, 1071111800,
|
||||
933776492, 26114960, 49888778, 1808107515, 1092989296, 754848337, 1336994364, -1987450448,
|
||||
-691190146, -1803870839, 1110716866, 1173269113, -391000050, 2014216908, 180756301, -382891013,
|
||||
-1908154585, 1580737629, 1080267957, -125532248, 2094530239, 2132964485, -438596348, -760299445,
|
||||
1058181869, 2050816800, -1534429037, -62552782, 824524142, -818590371, -1857695907, -684762866,
|
||||
-156556543, -902759995, -880795194, -1387351132, -1263017515, 448006597, 201038266, 1929826313,
|
||||
-455367306, 672963027, 2000073013, -1546842042, 446341090, 1001696686, -779919012, -347722602,
|
||||
-1342821677, 1639571150, -835315755, 1505585376, 367004975, -2035864404, -1786623553, 1249724913,
|
||||
182435312, 1444514513, 1815333708, 1333772382, 299664001, -284691169, 2034403374, 1423310887,
|
||||
-1319051884, 1557286441, -445198266, -251809030, 1602786123, 944036382, -1020529634, 258344235,
|
||||
685254367, 1838964943, -156674528, -979736602, -538312836, 234643178, 211152102, -635498640,
|
||||
-1036733933, -1347589147, -565609042, -1358714165, 508618483, -786364693, 2071450261, 1206956772,
|
||||
-678931458, 167690617, 144698821, 1719720781, 1575869280, -1343221123, -1766469944, 284991647,
|
||||
-717305514, 892653651, -1368347075, -615701972, -730369849, 1360396003, -1869287623, 1778269052,
|
||||
-586061545, -699517114, 61530249, -1860611767, -519660852, 1841085925, 1555610093, -399979337,
|
||||
-790345742, 422355947, 2007965433, 2044952550, -1712164595, -102915702, -693865324, -1894042487,
|
||||
-1285020072, -215883074, 95833252, 1625818040, -1055951680, 513067085, 1825246558, -553461652,
|
||||
-1923361799, -1869480206, 567232636, -1751727150, -1832301399, -108136455, -1312244126, 14006795,
|
||||
850221366, -382389732, -1741556188, -1317464467, 1948314870, 753994471, 1028235947, 342494132,
|
||||
-1862256693, 723808794, -234257642, 1609928369, -802733456, 1315831915, 1436072885, 1224767136,
|
||||
2144557791, -1839965886, 224821018, -1461697757, -1080386760, 1638573498, -1188173812, -325181523,
|
||||
-1750676219, -1780415850, 698793362, -908352052, 299746482, -161660934, 1938166833, 800297005,
|
||||
56640033, -1214932666, -1248124842, 1822796868, 1777615881, -718517774, 1908159957, 1733053281,
|
||||
1851844331, 1283519375, -1771494956, 2060179999, 1666129209, 1919453531, -498145770, 697567008,
|
||||
1855487148, -1587163491, 565216434, -1477877933, -925662919, -806492585, -1201439047, -1424534232,
|
||||
1788616523, 69414717, 655893636, -1175978556, 24787512, -861550001, 439525754, -190433174,
|
||||
-383811606, -508589783, 1441608687, 608181366, 1539467064, 925903122, 697209654, 1878283393,
|
||||
-1967567432, -1659677763, -249658183, 847096354, 397741956, -125334541, -1286840731, 1016461908,
|
||||
-997968592, 1795331475, 1856856501, -1716726445, -582181331, -887091847, 426964855, -609219941,
|
||||
-1456232632, -483467616, 1069260754, 972242064, -1406786247, 1954194029, 52627891, 1212755081,
|
||||
2117436668, 281073392, 741537353, -483063506, 1850906286, -244876135, -270818140, 1817568823
|
||||
};
|
||||
|
||||
for (int i = 0; i < refInt.length; ++i) {
|
||||
Assert.assertEquals(refInt[i], mt.nextInt());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,117 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.apache.commons.math4.random.Well19937a;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Well19937aTest extends RandomGeneratorAbstractTest {
|
||||
|
||||
@Override
|
||||
public RandomGenerator makeGenerator() {
|
||||
return new Well19937a(100);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReferenceCode() {
|
||||
int[] base = {
|
||||
740849862, 1202665156, -199039369, -259008301, -291878969, -1164428990, -1565918811, 491009864,
|
||||
-1883086670, 1383450241, 1244617256, 689006653, -1576746370, -1307940314, 1421489086, 1742094000,
|
||||
-595495729, 1047766204, 1875773301, -1637793284, 1379017098, 262792705, 191880010, -251000180,
|
||||
-1753047622, -972355720, 90626881, 1644693418, 1503365577, 439653419, 1806361562, 1268823869
|
||||
};
|
||||
int[] init = new int[624];
|
||||
for (int i = 0; i < init.length; ++i) {
|
||||
init[i] = base[i % base.length] + i;
|
||||
}
|
||||
Well19937a mt = new Well19937a(init);
|
||||
int[] refInt = {
|
||||
-612874471, -354976292, -1838197125, -1781560577, 278390997, 1214938280, -1752615390, -760835246, -1712883765, -241205782, -145390202, 495649160, -514388259, -1271015916, -1640000013, 849273623,
|
||||
-549729394, -1206917255, -545909692, 811925434, -1665729633, -1525292882, 1416246482, -153220826, 1148868872, -326143196, 1724979062, 1790931148, -1648679618, -439051683, 112482777, -1484051520,
|
||||
-1881272572, -1270447031, -1216102401, 1579107248, -1224395621, 2144411988, -416216641, -1529222361, 1628987080, 164445245, 1506928916, 928145916, 1436000427, 862025970, 560077705, -1887251027,
|
||||
-514360858, 1735094506, 475624879, 1755802355, 295448361, -155399225, 3972415, 1368201076, -465126094, -1622687259, -246099304, 1798631152, -1937269102, -1700560396, -293352622, -896632303,
|
||||
-2088933220, -194382452, -480218162, -1618517785, -1925031481, -150217434, 1678937261, 2130832364, -485546678, -1499224981, 1430390884, -1895417302, 210514746, 1781140999, -1940853105, -1238099647,
|
||||
485922557, -103223212, 633481679, -632946979, 695235541, -1661735272, 277603567, -958341538, 256982285, 1850270018, -327388076, -219053874, 1380560653, -1221689980, 1335863752, -545032383,
|
||||
-575291735, -1295623907, -140058298, 1063302709, -1290702617, -790401546, -170630961, -1203114473, 1458063108, -1212753301, 1546428514, 2112636413, -1463028928, -1812598032, -883529486, 1131084094,
|
||||
62042165, 2135819802, -1192342739, 98361522, -1341042205, -475283063, -1632033747, 1745196892, 168608689, -914987039, 274428907, -881357258, 167940012, -1975737532, -903960486, -1370984244,
|
||||
-589352935, 1783633514, -570111010, 71495377, 194463285, -1243905021, -1398490898, 221691209, -55728834, -638916786, -770622372, -1911651810, -295233027, 301467998, 2058638784, 681490183,
|
||||
-1547865078, -1668135684, 1299261826, 1649468635, 287995017, -2076844852, 1193468826, -853948258, 120082777, 1051829542, -1288514343, -159456430, 275748820, -480127107, -604943233, -2138088332,
|
||||
1202614819, 1427201263, -1906344469, -1230779533, 1690367192, 733159097, 794410312, -1114452505, -1601554413, 976747949, 1517787154, 2091780205, 1052078906, 1919282771, -191013374, 1805397142,
|
||||
736939268, -1056272823, -727464316, -659459005, 797803875, -1104633884, 1042342081, -24514837, 1919469940, 1903722546, -814157872, 1605407665, -262351256, -288949635, 729204844, -1132605534,
|
||||
745453338, 387915035, 1094173337, 2100279147, 156863702, -257377544, -719587984, -1496015613, 1908993744, 2016957554, 918749666, -135963651, -1356808639, -1711185741, 1472589240, -398100149,
|
||||
628791415, -1381837652, -1820702771, -593586943, -1456631279, -1837975351, -1394249972, -556916726, 833231177, 43449750, 1029237092, -2086437337, -459463076, -533031784, -1739648287, -1374722961,
|
||||
2024908394, 1389678488, 2018558, -1391707864, -795935743, 904816957, 836583280, 1766194531, -1374431014, -904437876, 2030248636, -265724199, 2056758426, -810499837, 887193593, -77811488,
|
||||
1496312336, -1874348275, -456193866, -2137130942, 868120387, 29025455, -1999867716, 2001322335, -579152815, -390892056, 1592011837, -306394879, 93636886, -190879994, 1923358153, 269052141,
|
||||
-396050253, -987531729, 480350991, 1276744541, -1445571957, -957571005, -2046270221, -1715395752, 1113585628, -1782113514, -697560146, 835320000, 1014320959, -2119834109, 460056841, -1464772991,
|
||||
-1282790418, -2120806165, 86176097, -731086307, 832497517, -1876684928, 541008240, 551124479, -450919132, 647860281, -2115397586, 979247589, 1095559204, 1927958688, 169497703, 1999579054,
|
||||
2019745038, 1656022059, -1109662138, 375237154, 1450814436, 919988416, 849761266, 1457057327, 1771166577, -1639880487, -852488298, 1767063646, 657295386, -585561879, 740792583, 1664558308,
|
||||
-654749506, 1109275990, 182597559, 1106789745, -1806628480, 25948116, 1748374299, 196057325, -164213209, 1687024594, 782029276, 1879737947, -1528219611, 412585737, 1190325629, 1985821911,
|
||||
-1272945202, -1238637137, 465818730, -1537670961, 1131953615, 905623579, 609183424, 1138422991, 1522974699, 589719061, -1310894604, 890952933, -885204790, -393535694, 1238408670, 1780660354,
|
||||
677803525, -1121509064, 1553148616, 1109165936, -1450120385, 1525252521, -1354897489, -595402189, -1274551767, -869281409, 1788815975, 2020262116, 1124100185, -400839020, 310574108, 1354413045,
|
||||
-1310514485, 1895732085, 626639054, 1667355357, 2065637178, -1889009143, -440157749, 1762849463, -1693853642, -56602956, -930874188, -398470740, 778356402, -2113156881, 42854964, 1844399604,
|
||||
-2098310302, -1812029757, 1441188713, 899579267, 1266994172, 1841370863, -660740252, -43254718, 1124500192, 1884907320, 879997211, 1775139845, -1360112721, 1630490057, 362567879, 1113475029,
|
||||
290319279, -1209506867, 398146039, -957742350, 1185761854, 1519676447, -912689915, -1117128973, -305563462, -1928033363, -1766324543, 1702753492, 1696951912, -1895072395, 932663591, -566548128,
|
||||
991675996, 56529814, 980735023, 718166662, -650028466, -886842051, 1857048587, -569023569, -1820572202, -851452711, -958700452, -621825633, -65649888, -510143183, 761267599, -1692108035,
|
||||
1729071710, 1623630864, -53498654, 267235687, 659201413, 1152882627, -824194574, 356636960, -502391121, -538453360, 66115376, -1633290370, -1522088932, 268949070, 684499443, -859474501,
|
||||
1586764345, -1515639709, 319695602, -307025150, 69076508, 1050726785, -1340930110, 552191600, -207852941, -273572993, -539580440, 710343120, 1957076127, -1107172811, -561518280, -1775022699,
|
||||
1978792904, 1935531451, -2084046304, -419742902, -737652926, 614022023, 1676952428, 769892939, -1092786807, -1117113223, -266029995, -350150999, 207738542, 1964896575, 48805284, 1736500159,
|
||||
551289617, -1847923501, 1856609505, 2007480480, -681860219, -1198106493, 1483591043, -523895316, -1814473078, -1521087404, -1348859926, 1298056897, 1813789478, 946683654, 79196400, 1766250931,
|
||||
472737685, 1764634332, -1844726079, -130619045, -508713868, -1762537125, 1010108863, 170107098, 1705386380, -1139681802, 183739097, 1662699401, 1842694501, 1714633805, 46208876, 616720693,
|
||||
-252553427, 1986302230, -103130254, 1943225981, 110746655, 553260552, 1588938073, -1934623163, -2144781332, -2086217416, 1941265852, -781953226, 1216234254, 605543697, -710872598, 2048636577,
|
||||
-1986927728, -1007017623, 1243051501, -614249563, -2128221291, 581579813, 1173464240, -1906830937, 261329601, -1805974103, 769823490, 1858731164, -561762071, 516417430, -1221329437, -825500715,
|
||||
1091364656, -993658663, -1475434188, -1070804384, -1876492082, 899494424, 683486936, 878807455, 56642807, -1268202879, 1379172046, -1386869373, -1158233876, 1759190552, 1597629789, 1411151497,
|
||||
-1254268471, 1075936979, -918778269, -2132675184, 953140888, 1906982077, 1154200766, -365384600, -1142488826, 708535121, -2134869964, -1531201665, -2100526761, 1268256467, 2071480803, 193135243,
|
||||
1374158182, 989505347, -933612202, -2134839213, -1302795271, -2092029041, 1812014826, 2090855917, 2005348528, 606434393, -60141386, 11156360, 539516285, -122485034, -893237911, -978127424,
|
||||
1509901816, -451029719, 428544700, -1622965963, -1993611605, -1989324583, 1104111587, -795138585, -899552401, -2110167769, -234502445, 1586963605, -503778455, 529261062, 325327284, -106186403,
|
||||
65369563, -1475700698, -228624261, 715975009, 1099352363, -1796883396, 1376542700, -308942420, -344940451, -395389249, -1562737166, 1869802677, 1273494710, 2075587668, -789570273, 1563347596,
|
||||
1142901755, 1676422422, -1729157809, -1399423717, -1814262429, -1809707284, 1393992342, -570246212, 1065528749, -781643849, 1218667301, -1097949471, 1305629790, 901301039, -704762030, 360582612,
|
||||
1411910672, 1848068741, -614500891, -146889637, -913903597, 723527277, -147033328, -199273155, 734997691, -2072735286, 2129258691, -1385074104, 931616624, 1065477319, -1543474555, -531410292,
|
||||
-2123119121, -1538464113, -1153585193, 1559931968, -654877011, 879865200, 1489681397, 1998864644, -1964160144, 163671782, -858364148, -323324233, 801208648, 705864113, 436184243, 643773864,
|
||||
2087594507, 134637265, -749956494, -1657343972, -1828172168, -27357303, -1145161336, -1192513644, 216148260, 611393153, -13752671, -358631090, -1211920749, 593572064, 657629904, -1445961088,
|
||||
-250704995, 1797542707, -2122311891, -316774825, -296303057, -868002056, -86697533, 2020588145, 1203427903, -1371839056, 669531557, -2031033836, 1323994690, 13703036, 785437772, -1465821554,
|
||||
-694756014, -2131068154, -1745448876, -1095891733, 936594025, -1119068454, 855423970, 1705079340, -905640608, 162297141, 1336619311, -344353769, -92608588, -1080573824, 2002293105, -2088030765,
|
||||
-1684198727, -129054718, -949437132, -127983221, -216664110, 1700146143, -711174649, 1500113839, 1212236226, -2017364219, -1263597675, 511929344, -323998524, -2021313185, 1803000924, 927670608,
|
||||
336267187, 1244256964, -1665390108, 991395134, -251232188, 1267445783, 1547951569, 740269916, 1776431169, 1687220659, 228229817, 271386089, -682906779, -438090344, 1190436796, -744272540,
|
||||
1879221151, 1145200306, -1730983338, -1119209309, 90826726, 1567861540, 1638852830, -1645384932, 1566909531, 1088584561, 1030555565, -1872052014, 720320695, -885053674, -321216789, 739907579,
|
||||
368580703, -443635520, 1232705619, -1355949988, -1047211249, -1571429448, 599299852, 1036970439, 1513838571, -51797291, -26647565, -1262878942, -916262582, 1579082269, -292007383, 1289013866,
|
||||
-1612184284, 1451738668, 448608569, 476432992, -1229609565, 786372409, 929928149, -150100614, 448155944, -1322320576, -856549627, 1057443268, -1536809554, 577508258, 584906122, 275295163,
|
||||
-604262071, -236043234, -1866434954, -2072447013, 646132876, 847562546, -310005953, -1104162658, 393261203, -730102354, 440824482, 1654535035, -1296359745, 1487359328, -977776604, -775827779,
|
||||
-1298695106, 519080622, 1697162240, 227873031, -371123123, 1273702312, -1710063656, -2138342344, 1139555478, 1531578907, -1498880699, 1183507362, 1875307493, -1649740413, 2135386504, -962458407,
|
||||
424161768, 504272962, 202204247, 1783466420, 2015579232, -676642965, 2067456450, 914480415, -620398841, 1880405399, 1406637142, 1951104977, 633496157, 224861869, -58659291, 994942775,
|
||||
-479000645, 1421449115, 100168104, 249754169, -1219011494, 1736303638, 364013694, -1750035055, -479217141, 1652913106, -2109452331, 1633842910, -1547663337, 936627493, -1152799743, 896955899,
|
||||
-1407742850, -523769014, 357161414, 872293304, 744895980, 720829676, -240843156, -111779524, 1292836315, -1792141538, 1946959925, 1181751089, -1120674052, 1185192575, -1387002557, 1973209255,
|
||||
-120887476, -766577735, -443913073, 786620227, 428564781, -101232106, -425959852, 198082021, 1173272226, -1744840378, -1621135606, -1539498583, -1101274572, 43399711, -1256764602, 1201920787,
|
||||
2049426139, 846545551, -2121520873, -1202939675, -470425740, 321987390, 1862019060, -951540342, -894238318, -430407175, -1662746491, 656574776, 1580373777, -431290218, 1645824323, -1953526979,
|
||||
-374682356, 474291752, 1071558425, 511038981, -760598678, -567797285, -1176476266, -268409005, -2130644484, -67970563, 1756046948, 1429860462, -1130984739, -124916495, -1544436836, -1863524031,
|
||||
1024916487, -1388636482, -1573205065, 892628956, 1831270021, 1176430590, 1158914682, -2006787098, -1228130033, 1516111488, -1499151347, 470546266, 1642603981, 1425140838, -1823071475, -1775267236,
|
||||
-1009380612, 164746986, 1129677098, 1842642579, -482342932, -507480364, 1656012309, 1981601761, -881042120, -511987083, 342447017, 381192578, 983008095, 741012865, -1877136350, -199211983,
|
||||
-452784912, 1929572576, -1678291139, -864375281, -1610561247, -1936356726, -749553767, -865893512, -567081879, -1303973729, -939636958, -622974563, 428284937, 1049237414, 852280765, 86648946,
|
||||
-1353851401, -1045422335, 898035731, -1636093996, -1083174191, 245046915, -359768226, -1028491655, 1051575118, 1774289451, 1839389415, -1594053468, 736707953, 1873556950, 401186168, -583669552,
|
||||
-88375334, 2002752071, 264506453, -1304812107, -759203942, -114958524, -1878903503, 841613720, 1910863820, -1738114003, 701455920, 1791058048, -1850960547, 1672292671, 1172188809, 604848896,
|
||||
-1607489375, 305370478, -948153885, -1971080100, -1848966954, -584538365, 39416319, -1689119162, 944942598, 1777111075, 1534005553, 2022718432, -25820385, 3077695, -315950520, 1859184648,
|
||||
-1397829266, -1666371809, 858913807, -610818620, 1554973298, 580023809, -1662988256, -408630026, 1316681876, 738204271, 942829881, -758486983, 780345857, 667165037, -2086803585, 789741324
|
||||
};
|
||||
|
||||
for (int i = 0; i < refInt.length; ++i) {
|
||||
Assert.assertEquals(refInt[i], mt.nextInt());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,117 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.apache.commons.math4.random.Well19937c;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Well19937cTest extends RandomGeneratorAbstractTest {
|
||||
|
||||
@Override
|
||||
public RandomGenerator makeGenerator() {
|
||||
return new Well19937c(100);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReferenceCode() {
|
||||
int[] base = {
|
||||
740849862, 1202665156, -199039369, -259008301, -291878969, -1164428990, -1565918811, 491009864,
|
||||
-1883086670, 1383450241, 1244617256, 689006653, -1576746370, -1307940314, 1421489086, 1742094000,
|
||||
-595495729, 1047766204, 1875773301, -1637793284, 1379017098, 262792705, 191880010, -251000180,
|
||||
-1753047622, -972355720, 90626881, 1644693418, 1503365577, 439653419, 1806361562, 1268823869
|
||||
};
|
||||
int[] init = new int[624];
|
||||
for (int i = 0; i < init.length; ++i) {
|
||||
init[i] = base[i % base.length] + i;
|
||||
}
|
||||
Well19937c mt = new Well19937c(init);
|
||||
int[] refInt = {
|
||||
2128528153, 327121884, 935445371, -83026433, -1041143083, 2084595880, -1073535198, -1678863790, -523636021, -1514837782, -736786810, 1527711112, -1051227939, 978703380, 410322163, 1727815703,
|
||||
-648426354, 636056441, 1954420292, 17754810, -958628705, -1091307602, 1793078738, -1680336346, 1792171272, 941973796, -2066152330, -1248758068, -1061211586, 262020189, 1276960217, -233886784,
|
||||
1767509252, -1811939255, -406116097, -742435920, -1349799525, 240329556, -332161345, 1488943143, -332244280, 2093328957, 674753300, -1930135556, 257111467, 63793650, -1964335223, 1315849133,
|
||||
-797349146, 1372022250, -1451892049, -1325138957, -870401239, -1294317369, 91490879, 386205044, -704074702, -1230679067, 1513674392, -262996240, 1196007314, 1398903796, 803719762, -1750926831,
|
||||
-1268814180, 1233515404, 1498313934, -970591257, 611113671, -261632474, 1834097325, 1709440492, -150396854, 2120561003, -62645660, 479080234, 1535125050, 1823378695, -1129289329, -1095198399,
|
||||
2092564733, 78836308, -692015409, 1647147229, -1847922219, 1838279320, -848333841, -1375151778, 920238861, 1512628290, -749439404, 288851918, -427218675, 679640964, 425700808, -2077624511,
|
||||
-1929434455, -647176419, 650437190, -1926749131, -1564744729, 734494454, 108193743, 246246679, 810042628, 1952337771, 1089253730, -1874275331, 1428419392, -492969232, 1945270770, -201265602,
|
||||
-755490251, -624426214, -699605715, -113446478, 809091299, -1521531511, 1136505389, -523660964, 132928433, 1926559713, -1485314325, -508322506, 46307756, -1627479740, -589386406, -1855555892,
|
||||
584299545, 1272841066, -597242658, 925134545, 1102566453, -753335037, -9523218, -1778632375, 568963646, 764338254, 1259944540, -2000124642, 1307414525, -151384482, 807294400, 1993749511,
|
||||
-15503094, -709471492, 2104830082, 1387684315, -1929056119, 224254668, -733550950, -889466978, -1987783335, -437144026, 995905753, -1021386158, -1096313388, -1014152835, -1303258241, 1201884788,
|
||||
-1845042397, 1421462511, 980805867, 2143771251, 481226968, 1790544569, 328448328, 1995857639, -66668269, -1411421267, -222586606, 866950765, -308713926, -1048350893, 993222402, -1139265642,
|
||||
-871837948, 1145571913, 381928580, 35386691, 1640961123, -1192981020, 775971009, 594246635, 1603197812, -575106766, 2023682000, -1636301903, -718093720, -1666421635, -2146115988, 320593570,
|
||||
287355418, 454400027, 1112753817, 1751196267, 782077910, -1478447368, -1007557264, -862315517, -2035355952, 2123515250, -557641502, -1789932035, 879640129, 44167603, 791148984, 1382939723,
|
||||
-2135684233, 1825489580, 937345485, -1839983359, -1536880111, -1472578359, 1548052748, -1471535862, -14508727, 1509621398, -2134967452, -787485401, 815341660, -327905128, 1028096737, 866906991,
|
||||
-1585990806, 859229080, 234806270, 998518056, -1897890815, -900923587, 1179856752, 1529572451, 620486106, 1119836556, 1661285564, 2097404633, -1437490790, 265306115, -984880135, 1326751968,
|
||||
1280043536, 680210701, 155786166, 1550973250, -325781949, -597789777, -1939780, 1345275487, 1930450001, 941449704, 669301309, 693651713, -990721514, 582968326, 976132553, -1892942099,
|
||||
-1065070157, -711990993, -688974833, -1026091683, 1115346827, -1305730749, -1733626381, -364566696, -21761572, -37152746, -262011730, 1302722752, -1806313409, -767072509, 764112137, 1671157377,
|
||||
1837645038, -1021606421, -1781898911, -232127459, -310742675, -1818095744, -1128320656, -705565953, -354445532, -523172807, -433877202, 131904485, -64292316, 381829280, 229820263, 1797992622,
|
||||
1359665678, 978481451, -885267130, -1415988446, -356533788, -961419072, 1938703090, 708344111, 679299953, 744615129, 1328811158, 1257588574, 569216282, -753296151, -1519838713, 2016884452,
|
||||
1062684606, 1561736790, 2028643511, -1353001615, 886376832, 1466953172, 1664783899, 1290079981, -57483993, -1176112430, 1634916316, 1976304475, 1374136869, -648738039, 1058175869, -909000745,
|
||||
-1526439218, 726626991, 2066596202, 64980943, -26166577, -885900005, -1821546816, -1103727665, 730606315, -1324948459, -696956940, -1300869403, 1171578314, 797249074, -1600611618, 1928247682,
|
||||
307164165, -1482476232, -1886179640, 1306433392, 1945271359, -1272113751, -1285984081, -2057145549, 795047465, 1262569087, -1239828121, 1426641636, -786371495, 2120199316, 1273690652, 74457589,
|
||||
-1033394229, 338952565, 46122958, 1225741533, 2115308090, 678200841, -1618264885, -101162569, -1628976330, -1232839500, 468709044, 1876019116, 92723122, 233398255, -554960844, 38494196,
|
||||
-406437278, 2083528643, -1106878615, -340722557, -2123964932, 223183343, 108918116, -1014629054, -901344544, -838896840, -1908460517, -1763508731, -926890833, 1703791049, -667755577, 1694418389,
|
||||
791641263, 1095689677, 1119202039, -1419111438, -2012259010, 188017439, -1775110395, -1971099661, -1688113734, 131472813, -776304959, 1511388884, 2080864872, -1733824651, 1992147495, 1119828320,
|
||||
1065336924, -1357606762, 462963503, 1180719494, -202678962, -892646595, 605869323, 1144255663, 878462678, -1051371303, 872374876, 631322271, -172600544, -1552071375, -1939570033, 151973117,
|
||||
1640861022, 310682640, 34192866, 2057773671, -2004476027, -1879238973, 582736114, 900581664, -427390545, -1232348528, -535115984, 1321853054, 69386780, -1729375922, 1418473715, 1022091451,
|
||||
496799289, -80757405, -1903543310, -1128846846, 1703964, 1984450945, 856753858, -812919184, 775486323, -1376056193, 638628840, 314243536, 1030626207, 644050997, 73923896, 362270613,
|
||||
236584904, 1463240891, -223614432, 435371594, -751940030, -124274553, -1991092884, 1579624267, 1249632649, 157589625, -345229739, -366245207, -1399995986, 1651729983, 1965074340, -1108970305,
|
||||
1163690769, 1732013523, -1461252895, 669755552, -476503675, -264578685, -32813949, 288222188, -25734262, 106040916, 1654395626, -365148479, 2014455846, -2040447994, 1351639280, -919975757,
|
||||
-1970412139, -47306532, 222377665, -363434917, -1091717516, 2090685531, -1221091649, -1729649190, -1239406708, 1064945398, -105437479, -419675255, 74701669, -12862899, -498269844, 1566898997,
|
||||
-1872838355, 1596887574, 485902962, 469225597, -881763553, 1307841032, -1642872487, 1388543045, 379792876, 1095683384, 840780732, 1934378038, 1851278350, -1359389423, 130868458, -313448799,
|
||||
-663624816, 1031714153, -608443411, -205137499, -1849464427, 1973593637, 1068741808, -1420655961, 1188762305, 954044841, -995454462, -1818101092, -1937201943, -324541290, -1520603933, 572873173,
|
||||
-554764496, 1051557081, -1245136076, -985349536, 329320398, 1787901464, -37803304, -1759310177, -1463492617, -1861729663, 1251768782, 256937091, -779036948, -2049893864, 1256022877, 1228075657,
|
||||
-1550195255, -611319853, 1190797155, 2047604112, -576077160, -1532843331, -1324899394, -159729560, -622525946, -1080302767, -236033484, 1895243903, -410123689, -1944154157, -681781021, 1208453003,
|
||||
579595878, 1303914051, -145607082, -131567277, -1917288455, 894217359, -175688726, -1585480723, 663691440, -1140068263, -641711178, 1596080008, 629197693, 976422358, -1570451095, 525923776,
|
||||
895046136, -504151767, 1602553020, -1233054923, -1798474837, -1488857895, 1055782627, 261863143, 1879276655, 488240679, 1910982611, -1919441259, 370435945, 1265230086, -1293284428, -1503576227,
|
||||
2076963035, -1379628250, 1157098875, 1984461153, -1947837397, 1705880124, 1453607404, -1233649748, 1479943773, -863878721, -862415630, -736723275, 940306358, -1596000684, -1174889953, -615723892,
|
||||
-885006597, -1796723178, 1844159055, -188942309, 2107251811, -1675486996, -1009475178, -859263556, -431866963, -9593673, -1878920923, -104853791, -1535224994, -69315537, 586690130, -1292234796,
|
||||
1378749456, -301873019, -319297563, 1677205851, 292450579, -1289441171, 1788113680, 1907606333, 1464711611, -1372023606, -1978832445, -1772259768, 1949124464, 1818322887, -1138036603, 1249727628,
|
||||
-1474866449, -1868013169, -1384567593, 717007936, 954189997, -1900561040, 738470389, -158973180, 1732860784, 1936031206, -1133354740, -1173166665, 1432976712, 852636081, 1732064691, -1831788120,
|
||||
1273933579, 455403217, 1988395890, 106493468, 506092152, -610530423, 1698053512, 1311747476, 1969503012, -1887461759, 1613543073, 903200334, -737865837, 325656800, -1234001200, 1492148864,
|
||||
2009861533, -368262605, 1091338541, 2076108119, -961392337, 1835877112, 316250307, -853333391, -2125443777, 815363504, -798707803, -158146540, 690786114, -530775684, 1203556940, 1611485582,
|
||||
-1661412270, -53184506, 2126287444, -232222229, 1559486057, 283532250, 1202760418, 932144172, 1082594656, -570104011, 413509167, -995027177, -996477516, -540544, -745537167, -712135469,
|
||||
-996294983, -592787198, 1889840948, 1314628747, -394266926, -682316577, 456447239, 1728806063, -396279614, -43387643, 1915717013, -861574144, -1078710588, -561401249, 1111464540, 63643984,
|
||||
-1693870413, -968369980, -1053148188, 708799038, 1883537988, 373371671, -156410415, -1596483236, -1846890431, 888692915, -1025632583, -1666477591, -343066267, -2059058792, 641501628, -1744347292,
|
||||
1648632991, 1743540146, 2020952406, 164014499, 990508262, 1706408228, -1236471842, -347116260, 1843634523, 827255665, 300519853, -1265974830, -547247177, -583064554, -1995437077, 689210107,
|
||||
-93151393, 835365056, 1706367315, -1605902756, 200954895, 431093688, -277573364, -928486713, -552221973, 145432789, 1128919795, 1675095586, 1930359882, 1215849501, -1447770583, 657776490,
|
||||
1885869860, -1629237204, -868897479, -1258169760, 1828140195, -883850439, 463933909, -347361158, 1478116648, 801176896, -1501915899, 1017335748, -1654508882, 123994786, 1588785290, 791166651,
|
||||
-1523108535, 340411166, -496474762, -1189711141, -7392628, 2045171250, -1245366209, 834787230, -1346883181, 2034209454, 737043362, 898803323, 1983089087, -1845404320, 9585188, -1180608323,
|
||||
1665100606, 1949474222, -211115008, 1151308295, -2132174259, 913126312, -2085061672, 1419864120, -1134542954, -53833957, -246913211, 468382370, -1759479323, 1136686211, 1307012488, -2036299559,
|
||||
-1346099736, 314743106, -1683101865, -947151948, -234529696, -2103334293, -279256894, -1484257, -1053953017, 1801205399, 941594454, -874119215, -672865187, 762284205, -1494975451, 486607927,
|
||||
-898264389, -1711861093, -212572760, 2106484281, -1610786470, 1352525590, -837779586, 1568282001, -593019125, -1146260782, -1595879979, -640781858, 1107692311, 1547132709, -1928385535, -2057772805,
|
||||
634887038, 329772618, 942136006, -864405576, 501883884, 1537141484, -1180626836, 1123055420, 1090885851, 421662750, 2033111605, 1710917425, -1118058244, 74321279, 257328195, -1199940697,
|
||||
208625996, -442341447, 808119183, 1166827075, 1177417517, -1856155370, -1464837036, -60624923, -1306220638, -91104698, -1434621430, 548899241, 37351476, 1478278431, -1255061434, 248470035,
|
||||
-104642597, -1865169521, 1418373655, -1660810523, -2129015436, 154612798, 276575732, 1930338442, 179503250, -929294855, -39452027, -1377657544, 1442322193, 1137511318, -432158653, -984801987,
|
||||
743099148, -1118893528, -904123623, -1273146363, -1884800406, -803169061, 1254123158, -484252077, 317646844, 404246525, -1230293916, 1121445742, -19657507, 652967153, -1055406692, -468950719,
|
||||
-1493532921, -1447624258, -1369679689, -1517000228, -145853307, 1518006526, 1591195514, -1475557146, -909722097, 2103182976, -406830579, -2124025254, -1804819507, -1357512858, 567321869, 409048156,
|
||||
567805180, 1749009386, 1762759722, -1770324077, 1271140844, 468219092, 955792405, 1911965665, 1876314424, -718200715, -1278883927, 1392281730, -120519585, 851473793, 245054754, -33369039,
|
||||
-284877584, -479534880, -212346563, -122017521, -1461429983, 1331007370, 1788621721, 1739036536, 1446350953, -1985448033, 685528610, -1386434659, 1368233993, 2021786790, 1596478397, -1716635278,
|
||||
-2011083017, 171876097, -311529197, 687812052, 377000657, -1055547517, -1499047842, -1818434951, -120863666, 33888043, -1387509273, -541540700, 1162597745, -1331415338, 1931708792, -850270000,
|
||||
663845594, 1536495943, -322924971, -1380272203, 261190298, -204874428, -2104974031, 883819928, 155808204, -1454446035, 1323388464, -1696505728, 1549800285, 1018150463, -1327715703, -1582480640,
|
||||
1013659809, -1820360082, 1666498787, 1406120540, -196541482, 1248470531, -1250433281, 836375878, 177646854, -1927020253, 2145878321, 689712096, -596605921, 348283199, 1916993096, 481356808,
|
||||
-339687826, 1219340319, 718895887, -2007521340, -1859185806, 2042164737, -58146784, 742449142, 1930754708, 780832111, 715056441, -1393886151, -8150527, -599607443, -537300865, -1212516084
|
||||
};
|
||||
|
||||
for (int i = 0; i < refInt.length; ++i) {
|
||||
Assert.assertEquals(refInt[i], mt.nextInt());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,117 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.apache.commons.math4.random.Well44497a;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Well44497aTest extends RandomGeneratorAbstractTest {
|
||||
|
||||
@Override
|
||||
public RandomGenerator makeGenerator() {
|
||||
return new Well44497a(100);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReferenceCode() {
|
||||
int[] base = {
|
||||
740849862, 1202665156, -199039369, -259008301, -291878969, -1164428990, -1565918811, 491009864,
|
||||
-1883086670, 1383450241, 1244617256, 689006653, -1576746370, -1307940314, 1421489086, 1742094000,
|
||||
-595495729, 1047766204, 1875773301, -1637793284, 1379017098, 262792705, 191880010, -251000180,
|
||||
-1753047622, -972355720, 90626881, 1644693418, 1503365577, 439653419, 1806361562, 1268823869
|
||||
};
|
||||
int[] init = new int[1391];
|
||||
for (int i = 0; i < init.length; ++i) {
|
||||
init[i] = base[i % base.length] + i;
|
||||
}
|
||||
Well44497a mt = new Well44497a(init);
|
||||
int[] refInt = {
|
||||
-1464956854, -1524360321, 986845646, -182050548, -818943186, -1744848370, 1392434650, -182648505, -2026593838, 1254866610, -410459761, -1392048371, -968730026, 1485793687, -728749746, -112685463,
|
||||
275126404, -1101838984, 1193096287, 443511615, -510869213, 549869992, 1974458428, -1217587840, -335835016, -2048974745, 1066947099, -611611187, 1978925459, 688164478, -463344808, 56995910,
|
||||
699288809, 606392470, 117418673, 1948706703, -485598135, 385841705, 1725261146, -919553921, 70643668, 2128611684, 1720197347, 738706713, 1162026860, -611442152, 1469145601, 2051653750,
|
||||
609067755, -1971782890, -971114565, 776260144, 1619791127, -1547233838, 1502505722, 913168193, 1761269649, 81782996, 62251540, 1519079156, 1239007000, 489633356, -800433470, -2107278046,
|
||||
495320431, 269446836, -2013306553, 1074614697, 1645125348, 584369930, -405429577, 1211134012, -2060113546, -2047824, -443978800, 271218497, -1002185964, 1519315874, -695096464, -79101601,
|
||||
-1521653608, 192426133, 1159511202, -1354494985, -477280535, 583522228, -661741458, -1251175621, -369487281, -2015449518, -2102058930, -645264919, -925270025, -1674575999, 1363844609, -831732660,
|
||||
-1668989157, -1861246633, 83763283, -1056074975, -519054258, -1546386261, 1691674654, -885968657, -1189571815, 2095154843, 1686743191, -1859471265, -261593938, 1721982136, -491120252, -949699153,
|
||||
642525852, -2005306625, -1004765905, 742736856, 1653443876, 788423835, 1536155740, 879514143, -1510757104, 115238646, 28600662, 1485490803, 1272460710, 523153480, -766782926, 1332478031,
|
||||
528775440, 302965264, -2046891123, 1108139271, 1611601128, 550846467, -439082190, 1244786747, 941120547, -35568474, 1756370964, 304870369, 1902684028, -408710726, 1673189520, 1180987663,
|
||||
-1488131864, 158973303, 154514890, -1387953397, 1453732833, -1342263302, -628153633, 4710424, 619931109, 721411332, -2135645486, 1688696681, -891749588, -1641122924, 1397432310, -865254619,
|
||||
-1635468227, -1827787970, -1311416657, -1022618057, 1411688086, -1579840139, -637954674, 2115653281, -1155985079, -1043532593, -374286955, -1825883832, -227940643, 1688394137, -524577925, -983222470,
|
||||
-1955769926, 626525757, -2009760930, -1855453635, -676923169, 754966926, -291202391, -2126042921, -1477304277, -1409345382, -1264640578, -441993991, -17611930, -1576809974, 2137694350, 1299022733,
|
||||
-762509116, -1087399293, 819303572, -14571174, -719035481, -1644675278, 1492736905, -15038081, 974773023, 1087127339, 1790024863, -1493135734, 1936273291, -442361741, 1639666948, 1147532756,
|
||||
174955156, -1537685747, 187972574, 275303083, 1420277149, -1375787574, 1873043153, 38164241, 653451946, 687758113, 899667071, 1722219976, 2146668333, 587401069, -26582672, 2034645447,
|
||||
1401801794, 1043291001, -1277898614, 2116116828, 1445274301, 150534325, 469242183, -937704471, 171074779, -204638071, 1269913689, -771734064, -12280461, -1182158859, 1704390140, -263303749,
|
||||
-848503723, -1822849148, -634064465, 1130988864, -1515750310, -908815400, 1487214333, 994482967, 853103628, 1711185413, 1520342001, 1067859186, 1693632130, -603831333, 292236742, -800655385,
|
||||
-1467184928, 221125007, -1697377800, 1293953144, 1730537111, 1073329737, 519625212, 689636032, 1127394154, -1496469136, -1214585810, 822152197, -1572579275, -527866383, -996792678, -2058452887,
|
||||
-1133767559, 576275042, 1579109209, -295089371, 1502267384, -724281876, -911879875, 1131096177, 333026744, 1238706603, 1067340063, -745697708, -973992204, 1560446744, -664017057, -616056490,
|
||||
1099714049, 674159948, 383625825, 1411443110, 1862818263, -1896254899, 1322476914, -719144734, -1540101945, 988154902, 781856577, 2013381051, -2059071359, -142073207, 60252832, 2052050421,
|
||||
-666391497, 376633738, 1663011481, -1706886481, -1870003191, 1003819645, 898131216, 778824906, -656875645, -1730811011, -1751653787, 2056079904, 231977636, 1831419220, -465545074, -1505266471,
|
||||
1034419975, -133864043, 1876779821, 1879792902, -100100435, -959264741, -472668436, 203584096, -46980157, -1478047098, -979669209, 809008494, 1279644171, 2055793632, 1385672419, -1756428826,
|
||||
-1790481031, -2089665073, -1608595011, 457322987, 1267418945, -19541848, -796352273, -1049973752, 30940894, -539710199, -1097391703, -779353550, -1328320498, -735447662, -918513196, 1516945649,
|
||||
1218919237, -251287485, 1826366637, 353082340, 889839220, 399638904, -1462573609, -618450466, 1429903706, 2095548034, 1486594475, -1053248922, 74346322, -357998703, 1790710495, -146359619,
|
||||
1581657509, -797737661, -920778913, 608399665, 646679359, 1861775150, -1014371223, 476735306, -1577737028, 383018939, 1234592859, 344770283, -472763155, 187217985, 1245828866, 1936329359,
|
||||
61243025, -1979390025, 903671173, 302699505, -1677126111, -1194113496, 835857595, 706998946, 70931462, 1374113464, -1464459699, -231081598, 1366205112, 396990527, -1615015619, -968458597,
|
||||
457632575, 24361353, -1120685182, 2101590608, 1654666456, -1208442054, 579414359, 1078056578, 217408674, -1560683025, 815178420, 1219326466, 450032327, 774403237, 54597342, -664057229,
|
||||
447132403, 50603973, 435640301, -1224073863, -1339908037, 1775470944, -1378119263, -1375189988, -1287971162, 29816317, -1313418882, -1824967031, 443540716, 11064217, -1463969487, 1967601549,
|
||||
124474667, 1230898256, -1741455555, 561643750, 933295231, -923145874, 245538199, 289478386, 200552280, -268887021, -1598221376, 1236123270, 318325803, 773964550, 191670680, 158043961,
|
||||
-762639146, -416703928, -721969492, 1664330785, -584949010, 1509045840, -2066001147, 1728613092, -1103375821, -1262079070, -2034789427, -418216342, -546365126, 1235751589, 1639799329, 2085089663,
|
||||
-697590049, -2007054256, -147701903, 209371702, -1868450893, 1241065116, 1537364837, -1035970557, 318040217, 150492098, 1841159805, -491979749, -1275490577, -1759443566, -697538216, -1589624976,
|
||||
-678703557, -189067001, 1539472677, -1396089831, 271512148, 180483983, 483714313, 703861378, 2122114992, -600097045, 522009268, 160429181, -744428886, 1541223403, -1211039718, -1167643980,
|
||||
1551471162, -816207368, -1429258613, 1350901561, 1934120609, -961643277, -214772286, -2128270227, -1561239720, 1493926966, 1376671007, 94966082, 221846150, -164351411, -51309876, 497148497,
|
||||
1233668542, 266257753, -773473851, 953946385, 420815294, -1390653175, 1834391782, 4704447, -891751440, -744104272, -1082756642, 1431640408, -1912055536, -159789461, -704946016, 1956368139,
|
||||
642279822, -374415338, 1562655802, -272964020, 1071498305, 667364168, -1546405154, 341389690, 1360662999, 377696332, -437020076, -1668574556, 1242655350, -756555890, 645954261, 1914624235,
|
||||
2134904445, -247737098, 143667521, -17668806, 1804148531, 414247300, 1030053929, -1595215075, 887532426, 553113691, 1173830167, -303724353, -280418143, -1143962122, -1898518451, 36464746,
|
||||
1189572700, -1549967582, 1093341440, -452303819, -731023001, 1111173883, 1678013973, -836458212, -842956392, 212774049, -845621791, 966282353, -823130040, 700410571, 619075141, -304785045,
|
||||
-1816233676, -1789653997, -166914694, 690663021, -669570330, 1098624444, -987380984, 452844935, -1089825546, 1221160503, 1217375341, 512281644, -1106887134, 1665404458, -1462594714, -207498587,
|
||||
-789271490, -723469709, 512055365, 1445951882, 1692473633, -996873493, 1445046730, 993087194, -1666188562, -897427329, 1008869698, 1236029718, 1499207233, 1704947182, -1815799281, 686399988,
|
||||
-475436580, 1588892458, 884859588, -471913926, -487416631, 1323960741, -1257612174, -468909314, -1866654496, -1417895838, 1707647971, 997140465, -1358794225, 1929422460, -605622778, -1587468566,
|
||||
469149623, 1121515927, 748484204, 1201983830, -1906623591, 76398473, 261109068, -796025669, -1964466661, 1739898262, -756850622, 1581369453, 1484675811, 484136467, -705983890, -1357931714,
|
||||
548520423, 741992908, 1017931838, -2078503520, 2097871343, 569233897, -91903627, 1864053450, -876129714, 336670307, -1950420274, -872316480, -662220291, 275724295, 703565412, 1334248646,
|
||||
-217559198, 1044090753, 743502488, -1518545318, 20614180, -768582053, 976522354, -25129962, -983639284, 71722595, -119236393, 368844119, -795808244, 696073964, 1379765302, 235083623,
|
||||
666280330, -1313689346, -643870520, 534522699, -250414377, -1239276164, 159264592, -1119503518, 1168161619, -1366518946, -1335653301, 248092140, 1390152547, 2051602724, -1023547981, -1479782621,
|
||||
-1785785862, 1609789158, -919124123, 1703200068, -852553456, 1573706142, -376011685, 305068766, -1231775451, -1536883494, -125122369, -896696968, 852651567, -458154391, 747781704, 1173040469,
|
||||
-1569200836, 312506093, -1680530410, 117086271, 794587661, -1231003908, -1048955503, 2119305423, 1636729108, -522378372, 1627421730, 545077470, -1683264872, 1486496559, -1793064672, 1908368749,
|
||||
-1226052295, 1399248776, -588193954, -1289386125, 534647065, 2126245059, -238362987, -1244573058, -1571832269, -2052693379, 1494767731, -528668449, -980826491, -151282847, -1468523556, 1876349941,
|
||||
-301654558, 1467960576, -741720848, -612158589, 92376910, 987915105, 1037689578, 793773489, -1387669541, 349490139, 564784004, -1161242130, 619703053, 2063233129, 190888106, 81845991,
|
||||
-1482466066, 283234313, 114355492, -1879406787, -1283370924, -1378903370, -730141747, 1570738286, -281348873, 2131743196, 795654462, -497365688, 437612465, 1928618254, 1433118279, -1801292119,
|
||||
-2059248836, -221673230, 163637697, -411319468, 244353317, 786753178, 489172932, 464627154, 1258915212, -229028334, -994675463, 1931657329, 1784181437, -97111947, 1728952452, -1329133577,
|
||||
-1606156362, 1341196121, 1679632329, -796545286, -1021125869, 1427825468, -214986389, 250791528, 1029777000, 90661677, 602529506, 2068040879, 1483801763, 2332097, -457467017, 672399614,
|
||||
1542769193, 1781253216, -1967165705, -2052227925, -1248173215, -1676554121, 292413596, 209649573, 1750689340, 1946874730, -832845570, 1774178655, -450175610, -431901779, 613330756, 1969434259,
|
||||
1251099237, -1320908513, -50659188, 273178515, -296290724, 1195998469, 1329813722, 759419114, 1003396150, -274557619, -548886303, -2055397788, -766678640, -464045978, -1835907569, -169406709,
|
||||
820751456, 1778613303, -1582073956, -1728391771, -2075389498, -1606584632, -1702107251, -15724560, 45610235, -1967510298, -671487775, -1841110041, -913365944, 869680052, -798103472, -1564096927,
|
||||
-918899909, -810066882, 428829752, -1413487973, -844240890, 1343914280, -689285374, 1827745702, -799686631, 1696465705, -726159000, -1381157526, 1649221296, 1791106481, -1872852642, -485685063,
|
||||
1534949133, -1611901907, -581776031, 242740701, -382394666, 668419384, 388297992, 748818886, 713804061, -1783774172, -1823401590, -1009098384, 2071462929, 1154475522, 1309810666, -1734475040,
|
||||
1212095416, 988288210, -1457428115, 1699730041, -1804729443, -1922824494, 1000076038, -226555981, 131425181, -1071582828, 357680377, 1574190179, 996651958, 965704429, -47651768, 243931978,
|
||||
808955117, -652323633, 544967309, -1199510217, 702795379, 997685748, 1593927308, 2119371055, 1451401230, -41992913, 2033816081, -1030495962, 1764010175, 457470691, -2001190141, -373358035,
|
||||
-1950331268, -1291674220, 642934467, -1825725718, -1555687487, 1664472129, -24722338, 1899539596, 78519318, 1662555805, 1744711308, -2142888582, -1597853572, 118030659, 1596713428, 404304267,
|
||||
-1350880388, 648702031, 1185458591, 1798138033, 819516445, -1466759682, -751277607, -879817426, -1931050435, 1465603177, -1402344216, 768491239, -1404853657, -1915685264, -1845859847, 313163207,
|
||||
1239598382, 1988767047, -555152530, -1925665864, -182399255, -1392390808, 64861291, -511875035, 1879964459, 918905020, -840773616, 459610189, -1522352470, -1821396360, 977274705, -60616465,
|
||||
-1846727880, 1208592937, -515359427, 1127607806, -395032287, 491869604, 2053794084, 568321750, 1597027438, 1355613070, -2069482724, 1899252555, 844726247, -625112193, 1146099491, -1037855139,
|
||||
1203928737, 1875686061, 994108281, 1471873396, 2026801570, 4941446, -1066074241, -983738686, 2037429697, -836521112, -633388883, 1221918725, 2137035208, -369891832, 372509548, -110916409,
|
||||
80517712, -658056946, 727893428, -1353651002, -475459562, -291323023, 1059377566, 591801919, 1018232602, -348255729, 1863827426, 246032476, -1026132864, -1356383176, -1224690998, 262442981,
|
||||
1257773681, -1738604660, 77131430, -1320261233, -2342727, -1817187590, -1883997191, 1367221809, -1863623746, -1132606249, 149024763, -1228275128, -578030399, 356914163, 2109691820, -880313621
|
||||
};
|
||||
|
||||
for (int i = 0; i < refInt.length; ++i) {
|
||||
Assert.assertEquals(refInt[i], mt.nextInt());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,117 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.apache.commons.math4.random.Well44497b;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Well44497bTest extends RandomGeneratorAbstractTest {
|
||||
|
||||
@Override
|
||||
public RandomGenerator makeGenerator() {
|
||||
return new Well44497b(100);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReferenceCode() {
|
||||
int[] base = {
|
||||
740849862, 1202665156, -199039369, -259008301, -291878969, -1164428990, -1565918811, 491009864,
|
||||
-1883086670, 1383450241, 1244617256, 689006653, -1576746370, -1307940314, 1421489086, 1742094000,
|
||||
-595495729, 1047766204, 1875773301, -1637793284, 1379017098, 262792705, 191880010, -251000180,
|
||||
-1753047622, -972355720, 90626881, 1644693418, 1503365577, 439653419, 1806361562, 1268823869
|
||||
};
|
||||
int[] init = new int[1391];
|
||||
for (int i = 0; i < init.length; ++i) {
|
||||
init[i] = base[i % base.length] + i;
|
||||
}
|
||||
Well44497b mt = new Well44497b(init);
|
||||
int[] refInt = {
|
||||
-102003638, -1254584449, 836441550, 1949705484, 653000494, 1579400718, 699652570, -140738233, 1164288466, 419933874, 366568847, 780567309, 1867405910, -350557801, -964350642, -1323492759,
|
||||
191502468, 398676344, 1568976991, 1005053759, 199053603, 31083944, 74697788, -1343941248, -1205631880, -1637961625, 361813531, -1706096179, -403340909, 1666226814, -2034962600, 1237102662,
|
||||
-1833248535, 1584255126, 1295661745, -1753848945, 1208145993, 930278953, -733716134, 192752767, 1692463060, 1727273316, 2122952931, -809025255, -992081044, -895539688, -419372543, -1835478922,
|
||||
2089629419, 1646590742, -1261083717, -1005462992, 1619627287, -1437723182, 1619689210, 1319393089, -1816963183, -150214444, -513482220, 1897815796, -1861960936, -1766444468, 2034653890, 585657634,
|
||||
1867016559, 696942260, -1536237241, -527055447, -1554805020, -1063992566, 1024799415, 1782080572, -1884276362, 129028272, 1427925968, -1154222271, -1383146732, -1580532830, -1907049616, -104299169,
|
||||
-1780913000, -2090815339, -1789809502, -1521443849, 1226625769, 1126090676, -2117094290, -449575109, -218982833, -695554478, 35923022, 1386126825, -95031305, -168657023, 436674049, -1137917876,
|
||||
-2045134053, -1025629865, 133144659, 64226081, -1966942130, 700813483, 344058910, -910646033, -212789479, 740360859, -1269028713, 1517763679, -664178514, -683718472, -71951996, 86583727,
|
||||
-1235669348, -1426987265, -166598353, 214190040, -1436967644, 233824411, 710927452, -1939548641, -433607408, -1075939594, -1549702826, -1310827917, -640604762, -696863672, -1282162126, -546470833,
|
||||
-1516734192, -513809904, -458526835, 708926727, -476643096, -2108375037, -2870478, -1460116421, 436587555, -948939610, 1891375124, 1944216545, 959034236, -1267038790, -1695098736, 1853748495,
|
||||
1594424552, 1270099319, 1139585482, 1837434635, -709909535, -457524230, -887118113, -241703912, -1888225819, -751575804, 1122280146, 1194255209, 949350188, 892826516, -791212042, -151203035,
|
||||
-859297731, -1979039938, 323603119, -1022065097, -1804294506, -385802891, -2127523442, -720380255, -1315859127, 999649487, 335041941, -1732821688, -1833409827, 535715225, -1285355653, 1206723386,
|
||||
-1141619270, 759796285, -1599504546, -1988521411, 1056668895, -852564594, 1056509609, -1831687977, 754168875, -1301144422, 922880446, -1502666503, -949791898, -1043870198, -1136941938, -1649670259,
|
||||
1342769348, 1692605059, -132279148, -1108038310, -14355545, -1611387086, 1651826569, 877600127, 1356160799, -759125205, -1300490081, -414938486, -201479285, 1958709363, 1513313540, -1396836908,
|
||||
1352702612, 1142506253, 52969438, -365142357, -1619054179, -1368514102, 1470750417, -1420830959, -843909462, -1679570143, 1447444607, 234551752, -1507452115, -1433234579, -680890000, -497305145,
|
||||
860408898, 263376761, 1537070218, -592353956, 1587852989, 1756653749, -2081320633, -1547020311, 723771611, -883819383, 1899879513, -268417584, 1058606451, 1665941493, -1630340612, -614737477,
|
||||
891313237, 1368950660, -1166187089, 296322368, -1908770726, -2120378408, 1245479677, 1879710487, -1705947124, 1018371589, -1715010575, -1096078094, -1749891454, 2130888667, 318647750, 554592231,
|
||||
-489121568, -1809605233, -1697905160, -953926536, -2013960553, -148884919, 1822739964, -1466301760, 141999978, 1946526064, 1323036718, 864390149, -2141665227, 1510602225, 1468408474, 1277039721,
|
||||
-1368096647, 180965986, 2140852057, -688071899, 819713016, -154385940, -1182972611, 1257224305, 1392607672, 1364245931, -1768434401, 323522132, -555278604, 474186520, -1178901665, -2137343658,
|
||||
1636421121, 1398987084, 1276656225, 1013316006, -955917865, -1537149363, -179145358, 342862050, 1172728007, 736300054, -1114656959, -1831840325, -1882353535, -442915191, -1206488416, -1818534411,
|
||||
25312311, 2100297098, -1562767719, 1762553519, -1853194231, -1152612739, -2020055792, -809572150, 848584579, -535789699, 1817604709, 1343773216, -602234204, 1739930964, -833790834, 501215449,
|
||||
-730104057, 1217783189, -681773267, -611951354, 978387629, -1516811237, 974303980, -1389665696, 2091099075, -727528826, 2116026151, 271935854, 613242379, -2100429856, 190004963, -1629612570,
|
||||
-1362888327, 175094223, -917873219, -2008308245, -401946815, 504218792, -1966525201, 4106248, 164895454, 226502921, 655865257, -610528718, 189428750, 1055978898, 17603028, 591024369,
|
||||
1127922501, -1546639293, 1994174637, -724136988, -673919372, -1665002120, -612145705, -793102882, -1904763558, 757565058, -2091240021, -2123324826, -1518702766, -802889839, -223045921, -1509216579,
|
||||
1195556261, 2079259971, -903969953, -1781800655, 1834950463, -956531922, -1152550807, -1116052662, -348802884, -1395330117, -91758501, -19115285, 1926930669, -1015793599, 545904386, 1617858191,
|
||||
716963473, 1917089719, -980914811, -212646927, -1634695647, -1857924568, -1462257477, 1273750178, 1060328454, -361604424, 867932749, 451213698, 405780152, 1165233215, 1877230909, 2103114395,
|
||||
1644330815, 1252998537, 1961603970, -1533101488, 1790456024, -38226118, -1306744489, 713676418, -1535871838, 1378109935, -338185548, 1647669762, -477465913, 203482277, -1949756706, -503326093,
|
||||
-638704909, 320186309, -1435581459, 907446649, -77384645, 537368928, -335347295, -1912061924, 547819174, -225549827, 1089455486, 463516297, -240127764, -85895271, 2053179697, -287394931,
|
||||
921878827, -933362608, -1178670275, -1200942874, -672571265, 574422382, 1441734039, -1814493454, 165751640, -176907245, -1170992192, -2123252090, -1435971541, 1591853830, -885477992, -792847559,
|
||||
1359875286, 1038392904, -2027255124, 687291425, -165513490, 1391146576, -1387080955, 794663652, -807189965, 667820962, -545384499, -1371368854, -689031878, 1504805541, -752825823, -1920047745,
|
||||
-1884874017, -350566320, -197152911, -181743050, -798415949, -915922276, 1790690149, -363997181, 1923116185, -1326427198, -1621079427, -1997440997, 1798118127, -2053110382, -159879848, -1286787216,
|
||||
1046436411, 1832030471, -389092059, 71686169, -76025260, 1914270607, 1854169353, 872157826, -1774323792, -575165717, -1919931724, 2051498109, -1176174934, -883578901, -1253047270, -1310573900,
|
||||
245466682, -1784824328, -1319912821, 1377340217, 1364313761, -408687373, 142333378, -1952335763, -1703126184, 316314678, 2030555423, 488640834, -1783293306, 2116925005, -428337460, -42966447,
|
||||
-476226114, -325172903, -1690748475, 852791569, 26490302, 85251337, -1374975770, -376283969, 982639600, 595119792, 376403422, 1574509912, -1509664496, -1901241749, -59019104, 358566667,
|
||||
341667214, 184541206, -550950854, -1897143732, 1595753537, -1236127928, 2014297822, -2033179270, -669806121, -1927596980, 1010735700, -581795164, 1922398838, -1456743538, -1633813803, 323177707,
|
||||
2002098813, -2099067658, 277393729, -671911622, -384463053, 2028267908, 367391785, 1270052637, -172839030, -650486693, -831800809, -1255138113, -137512799, 1904317942, -8229811, 707361898,
|
||||
-276859812, 50417442, 1487081728, 1577776181, 1994451303, 1237303035, -602016235, -1905218276, -1895725672, 1172978849, 801129953, -1819485071, -587985848, -2010386741, -1645226427, -850866837,
|
||||
816998708, 357665811, 1955856762, 1617902189, -1013761306, 146782652, 904185608, -500146809, 2085848310, 1917713975, -1823786899, 1994184748, 789196322, 1766857258, 1770685286, 58213029,
|
||||
-1699628994, 346827379, -1274423227, -5079670, -193099487, 1020296939, -1795904054, -1951053094, -43782418, -375403393, 1026761026, -207269610, 1364563521, 1578793454, 457809423, -534138380,
|
||||
-1052938788, -1897101526, 1449976516, 2052800058, -1145169719, 1476303269, 370625650, -325249282, 2165984, 1631432802, 1032336355, -1292978191, -1810172401, 725725820, -1162678778, 702624490,
|
||||
1387673527, 981825943, -556408212, -1108487850, -1782136935, 1582316425, -1752682164, 307235003, 1386486299, -1343636074, 1936875586, -1265279891, -345847069, 928241171, 239050350, 1859358526,
|
||||
-664776217, -823267892, 346651710, -867656288, -1907921425, 1362445801, 541145461, -192727350, 1649366606, 244694627, -488180018, 214008256, 2032125437, -1678591993, -264593820, 1309017286,
|
||||
-652451998, 1845366657, -703990120, -550186406, -630285276, 1782372955, 1650564210, -1127904234, -1407983860, -1119422877, -1565976361, -1913545385, 549841420, -1410323732, -1964467146, 228296551,
|
||||
-421026422, 1929094398, -266906424, 264810315, -2008122665, -1088278148, 141242192, 1871293282, 234634067, 1724159838, 1638271051, -837713428, -657941661, 168093988, 708605363, -1881612509,
|
||||
-1810496006, -193495322, 1889982309, -2050702012, -693694192, -1249780322, 718733403, -76349730, -188217051, 920912090, -1814078273, 2013358456, -1948845521, -198407575, -1248904632, 1182772565,
|
||||
1236791612, -1297489171, -1958468586, 1437011007, 390460941, 113068796, 1247982993, 2102889679, -1563524844, -128174212, -754095070, -1461699362, 943615640, -1013270737, 221253920, 1514140013,
|
||||
1596946745, 674222984, 616356702, 1811224435, -1764322023, -1653707581, -1702404459, 390678142, -209506765, -1398278531, -117061517, 1625861343, 659048069, -1490678943, 846536668, 210715637,
|
||||
1855458786, 1727745280, 1086729456, 1109111683, -985298098, -1813777567, -954599702, -1522494031, 1166103515, -191868965, -1048777852, -661271058, 1161457421, 1509090409, -919753558, -155431193,
|
||||
-1774302994, -366390263, 2090138916, -693431491, -1693888428, 1846774454, 925855693, 474383470, 208889079, 382195164, -283005634, -2095134392, 579927985, 1390765326, -1766119865, 900457129,
|
||||
-1503703236, 974952690, -107714111, 381338452, 1187256613, -860560742, 524103620, 1499506130, 197755276, -790802926, -406920967, -1972219791, -665721155, -113336203, 1037154436, -1185441801,
|
||||
-745541706, -546274471, 1988928457, -1975403782, -1167172845, 777779004, -1560935061, -140258712, -1243598232, -1394149587, -785002782, 311842991, -1025469277, -605350463, -1251538057, 537203966,
|
||||
597777961, -1845767072, -1556349193, -1491015509, -1935936671, 2093498487, 1908270236, -315396187, 1356362300, -2025658518, 630119678, 276190559, 510123398, -1266145363, -170152124, -151540077,
|
||||
-477900187, 1895894303, 1870333068, -1169891437, 353366620, 2111175941, 1691245786, 1318765802, -90993610, 921309517, 118241505, 367005284, 1624861072, 2010785894, 865255951, 1717799691,
|
||||
-80757664, -644944841, 136999836, -341686875, -1908076090, -1968934200, -346397811, -184213520, -511811333, -2118173466, -1086490399, 1795322855, -635494328, 415716276, 851044432, -904636831,
|
||||
-1972230341, -64337858, 571177016, 1248814747, -1351030778, 457872680, 1843549954, 1718960038, 815088665, 1812961065, 360686952, -1356586646, 1657802416, 1776192945, -786723490, -342254407,
|
||||
-236653811, 771014701, 906386785, -308057635, 1907957462, 206000440, -42143480, 900403654, -917549795, -310520796, -1713627766, 2061136240, -377977839, 891282946, -821163030, 328143584,
|
||||
1503793080, 551621842, -2086273683, -2070526343, 91195293, -1654389038, -1035734266, -336619597, -1220221027, -1468468844, 2105626873, -841372573, -122707018, -2013073683, 494461000, -2054807734,
|
||||
-67946259, 1914163407, 1941835405, -1027244745, -768123277, 419129844, -275750260, -171533009, 97756174, -17651409, -1578102255, 995291430, -1587462977, 692904675, 951632643, 1882101293,
|
||||
-1546298756, 2018418068, -1790777661, 1542305514, -1437624383, 469587009, -1647853474, -1318279028, 497228822, 726733469, 1693133452, -2091185798, -209017732, 126386499, 1056958932, -2105494133,
|
||||
754067324, 96463951, 83701151, 1101658289, 1485852701, 553783806, 1898769881, -1072031442, 1438062141, 1992540265, 1152252136, 1019391719, -175951257, -6691216, 989789689, 968359367,
|
||||
-1330392786, 1704963399, -998432914, -948060232, -1921688855, -975840920, 1360273515, -872810459, 12676907, -1908050756, 883609616, 65641549, -200365398, 1386653304, -1203665071, 1878689007,
|
||||
426262328, 315375145, 1900325181, 703658494, -765404895, 1070155172, 1399748900, -804264234, -1619419026, 1347225486, 230635292, 1093717835, 14020583, -2107039873, -968325341, -1679158691,
|
||||
1959784097, 1065690797, 1090615161, 1311445364, 865835426, 870016646, 574122879, 1842697922, -1289210431, -1914001560, 1672467629, -900366331, -1524066872, 136503816, -1910431892, -1431958329,
|
||||
-830367152, -1316233970, -801974860, 1560669382, -81784810, 401822577, -949103202, 943897151, -722666726, -96825841, -1092898846, 230567004, -70355840, -1398069192, -312953142, 1475420133,
|
||||
-622491023, 1661205388, -19071322, 6024591, 1473041593, 2053897978, -1346768903, 1484764721, -1552461890, 1287146711, 1613069307, 902497864, -1504480063, 375292915, -836353108, 2047602411
|
||||
};
|
||||
|
||||
for (int i = 0; i < refInt.length; ++i) {
|
||||
Assert.assertEquals(refInt[i], mt.nextInt());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.random;
|
||||
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.apache.commons.math4.random.Well512a;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Well512aTest extends RandomGeneratorAbstractTest {
|
||||
|
||||
@Override
|
||||
public RandomGenerator makeGenerator() {
|
||||
return new Well512a(101);
|
||||
}
|
||||
@Test
|
||||
public void testReferenceCode() {
|
||||
Well512a mt = new Well512a(new int[] {
|
||||
740849862, 1202665156, -199039369, -259008301, -291878969, -1164428990, -1565918811, 491009864,
|
||||
-1883086670, 1383450241, 1244617256, 689006653, -1576746370, -1307940314, 1421489086, 1742094000
|
||||
});
|
||||
int[] refInt = {
|
||||
1634813289, 1876773016, -973836208, -2130023652, -1045460084, -1834384857, 1691032973, 609714289,
|
||||
2033920362, 555915483, 6680992, 1958127415, 1866469645, -1471336965, 2049178762, -192324811,
|
||||
-2056050066, 810879705, 1405046309, -781317118, 1012782311, -1045081032, 728377508, 1473511660,
|
||||
290489070, 326666761, 2018299979, -1876688058, 1239968501, 1464625040, 2025151042, -101397407,
|
||||
1387902041, 210959839, 1366359326, -476473433, 153180037, -1607631523, -506743495, 17888738,
|
||||
313865008, -340504498, 586684079, 1243699375, 753162229, -646761694, -739189655, -210120185,
|
||||
-1856358726, -628255542, -1812798197, 1416288088, 1077967722, -846846208, 1379850409, -580183344,
|
||||
-1858959, 210859778, 295841424, 1492774865, -1415543680, -344870570, -1942779197, 1549510646,
|
||||
-389544849, 314254218, 11784988, -1311757368, 1719514841, -764610517, 1296788970, -994707050,
|
||||
783854563, 422654144, 387639079, 1219688425, 2144352572, -834212874, -1036550358, 935909479,
|
||||
-568610842, 1327498837, -588933178, 1910065754, -40851599, -182063170, 1302731458, 541311559,
|
||||
-1647345522, 805224371, -1721196679, 1518507830, -952689880, -433276260, 509675254, -777259954,
|
||||
1277810106, 284054896, 936042202, 2036836351, 1956412426, -1186403024, 287795400, 2135311211,
|
||||
720485927, 1500695024, -281656583, -1277937322, -1628968482, 1242814831, -2030700974, 1473867890,
|
||||
440813549, -1357033971, 28384076, 1602731216, -641465746, -609054347, 635938444, 1472898176,
|
||||
1476894555, -747974186, -1590337055, -884242108, -389736197, -2066984505, 1087103272, -1236446290,
|
||||
31657463, 1835715432, -468439078, -2132633204, -434609235, 258308151, 1851926761, -1630139159,
|
||||
-1344617241, 1969204215, 619463174, -174392624, 207475487, -1619828078, 1327980298, -83968178,
|
||||
445951782, -1786230541, 6279288, -580982231, 1550645552, 2006533941, 275746007, 455676647,
|
||||
2019637349, 1115547704, -1313120106, -516213449, 73752461, -1382448112, 398589620, 1319888048,
|
||||
-1595572334, 1566934536, -1735685764, -1509545339, 1458173912, -549395819, -618827040, 1516624531,
|
||||
1900757187, -1454200688, 965524719, 488355065, -1869294316, -810641680, -2059428251, 1454656431,
|
||||
1329120541, -232185900, -994996943, 1855980910, -452077812, 1565630611, 759842266, 1241435187,
|
||||
-1390456063, 1946400597, -2032319771, 683667881, 905911106, 1983310786, 120010546, 526018017,
|
||||
-1946881912, 205004987, -1307250612, 2130980818, 2052864161, 189839787, 1789478047, 406168885,
|
||||
-1145186347, 8507675, 1277188815, 1492619042, 2009819675, -1627411598, -851016743, -1828234956,
|
||||
1962622506, 2140398255, 236935165, -337237772, 1263419111, 516775236, -335741025, 1391328225,
|
||||
455979249, -1457534664, -657606241, 485648133, 1762116343, 1194889600, 817834937, 321150162,
|
||||
131159182, 290277758, -1876924740, -1770401129, 1291602973, -1003642974, -1580211929, 1520422021,
|
||||
-399171579, -24315308, 453805396, -659197747, -205656847, 466526550, 1444397201, 1178091401,
|
||||
-1157268826, -602394028, -1370668795, 1614896435, 1699071659, 1864753793, 1888518358, -1721244514,
|
||||
1812776767, 668822227, -297283057, 2130183333, -1169618692, 912860240, -2028253096, 1244694278
|
||||
};
|
||||
|
||||
for (int i = 0; i < refInt.length; ++i) {
|
||||
Assert.assertEquals(refInt[i], mt.nextInt());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue