Skip to content
Permalink
Browse files
Minor Improvement:
* Add final on private variable
* fix javadoc
* Use Array Filling
  • Loading branch information
arturobernalg committed Jan 18, 2021
1 parent b9f778c commit 881650c63cbeefa8ba7d2f9404cf8be5de1c6e25
Showing 5 changed files with 9 additions and 11 deletions.
@@ -189,9 +189,7 @@ private void initState() {
isaacA = 0;
isaacB = 0;
isaacC = 0;
for (int j = 0; j < arr.length; j++) {
arr[j] = GLD_RATIO;
}
Arrays.fill(arr, GLD_RATIO);
for (int j = 0; j < 4; j++) {
shuffle();
}
@@ -104,7 +104,7 @@ public class MersenneTwister extends IntProvider {
/** X * MATRIX_A for X = {0, 1}. */
private static final int[] MAG01 = {0x0, 0x9908b0df};
/** Bytes pool. */
private int[] mt = new int[N];
private final int[] mt = new int[N];
/** Current index in the bytes pool. */
private int mti;

@@ -84,7 +84,7 @@ public class MersenneTwister64 extends LongProvider {
/** Least significant 31 bits. */
private static final long LM = 0x7fffffffL;
/** Bytes pool. */
private long[] mt = new long[NN];
private final long[] mt = new long[NN];
/** Current index in the bytes pool. */
private int mti;

@@ -75,7 +75,7 @@ public class PoissonSamplerCache {
* {@code N = (int)Math.floor(mean)}.
*/
private final int maxN;
/** The cache of states between {@link minN} and {@link maxN}. */
/** The cache of states between {@link #minN} and {@link #maxN}. */
private final LargeMeanPoissonSamplerState[] values;

/**
@@ -69,7 +69,7 @@ public final class ThreadLocalRandomSource {
*
* <p>This should only be modified to create new instances in a synchronized block.
*/
private static EnumMap<RandomSource, ThreadLocal<UniformRandomProvider>> sources =
private static final EnumMap<RandomSource, ThreadLocal<UniformRandomProvider>> SOURCES =
new EnumMap<RandomSource,
ThreadLocal<UniformRandomProvider>>(RandomSource.class);

@@ -112,7 +112,7 @@ protected UniformRandomProvider initialValue() {
* @throws IllegalArgumentException if the source is null or the source requires arguments
*/
public static UniformRandomProvider current(RandomSource source) {
ThreadLocal<UniformRandomProvider> rng = sources.get(source);
ThreadLocal<UniformRandomProvider> rng = SOURCES.get(source);
// Implement double-checked locking:
// https://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java
if (rng == null) {
@@ -122,11 +122,11 @@ public static UniformRandomProvider current(RandomSource source) {
throw new IllegalArgumentException("Random source is null");
}

synchronized (sources) {
rng = sources.get(source);
synchronized (SOURCES) {
rng = SOURCES.get(source);
if (rng == null) {
rng = new ThreadLocalRng(source);
sources.put(source, rng);
SOURCES.put(source, rng);
}
}
}

0 comments on commit 881650c

Please sign in to comment.