You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2019/09/26 20:03:31 UTC
[commons-rng] branch master updated: Report the seed and native
byte order to the stress test file.
This is an automated email from the ASF dual-hosted git repository.
aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git
The following commit(s) were added to refs/heads/master by this push:
new 5fffb3d Report the seed and native byte order to the stress test file.
5fffb3d is described below
commit 5fffb3d888bb4650dc081cbf3204ad2232c16567
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Thu Sep 26 21:00:11 2019 +0100
Report the seed and native byte order to the stress test file.
---
commons-rng-examples/examples-stress/pom.xml | 5 +++++
.../commons/rng/examples/stress/StressTestCommand.java | 17 +++++++++++++----
.../commons/rng/examples/stress/StressTestData.java | 8 +++++---
3 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/commons-rng-examples/examples-stress/pom.xml b/commons-rng-examples/examples-stress/pom.xml
index 3c01926..04f315b 100644
--- a/commons-rng-examples/examples-stress/pom.xml
+++ b/commons-rng-examples/examples-stress/pom.xml
@@ -64,6 +64,11 @@
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
</dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.13</version>
+ </dependency>
</dependencies>
<build>
diff --git a/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/StressTestCommand.java b/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/StressTestCommand.java
index f1afaa2..32d9082 100644
--- a/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/StressTestCommand.java
+++ b/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/StressTestCommand.java
@@ -16,6 +16,7 @@
*/
package org.apache.commons.rng.examples.stress;
+import org.apache.commons.codec.binary.Hex;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.simple.RandomSource;
@@ -417,8 +418,9 @@ class StressTestCommand implements Callable<Void> {
continue;
}
}
- // Create the generator
- UniformRandomProvider rng = testData.createRNG();
+ // Create the generator. Explicitly create a seed so it can be recorded.
+ final byte[] seed = testData.getRandomSource().createSeed();
+ UniformRandomProvider rng = testData.createRNG(seed);
// Combined generators must be created first
if (xorHashCode) {
rng = RNGUtils.createHashCodeIntProvider(rng);
@@ -439,8 +441,8 @@ class StressTestCommand implements Callable<Void> {
rng = RNGUtils.createReverseBytesIntProvider(rng);
}
// Run the test
- final Runnable r = new StressTestTask(testData.getRandomSource(), rng, output, command,
- this, progressTracker);
+ final Runnable r = new StressTestTask(testData.getRandomSource(), rng, seed,
+ output, command, this, progressTracker);
taskList.add(service.submit(r));
}
}
@@ -513,6 +515,8 @@ class StressTestCommand implements Callable<Void> {
private final RandomSource randomSource;
/** RNG to be tested. */
private final UniformRandomProvider rng;
+ /** The seed used to create the RNG. */
+ private final byte[] seed;
/** Output report file of the sub-process. */
private final File output;
/** The sub-process command to run. */
@@ -530,6 +534,7 @@ class StressTestCommand implements Callable<Void> {
*
* @param randomSource The random source.
* @param rng RNG to be tested.
+ * @param seed The seed used to create the RNG.
* @param output Output report file.
* @param command The sub-process command to run.
* @param cmd The run command.
@@ -537,12 +542,14 @@ class StressTestCommand implements Callable<Void> {
*/
StressTestTask(RandomSource randomSource,
UniformRandomProvider rng,
+ byte[] seed,
File output,
List<String> command,
StressTestCommand cmd,
ProgressTracker progressTracker) {
this.randomSource = randomSource;
this.rng = rng;
+ this.seed = seed;
this.output = output;
this.command = command;
this.cmd = cmd;
@@ -622,6 +629,7 @@ class StressTestCommand implements Callable<Void> {
sb.append(C).append(N);
sb.append(C).append("RandomSource: ").append(randomSource.name()).append(N);
sb.append(C).append("RNG: ").append(rng.toString()).append(N);
+ sb.append(C).append("Seed: ").append(Hex.encodeHexString(seed, true)).append(N);
sb.append(C).append(N);
// Match the output of 'java -version', e.g.
@@ -635,6 +643,7 @@ class StressTestCommand implements Callable<Void> {
sb.append(C).append("OS: ").append(System.getProperty("os.name"))
.append(' ').append(System.getProperty("os.version"))
.append(' ').append(System.getProperty("os.arch")).append(N);
+ sb.append(C).append("Native byte-order: ").append(ByteOrder.nativeOrder()).append(N);
sb.append(C).append(N);
sb.append(C).append("Analyzer: ");
diff --git a/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/StressTestData.java b/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/StressTestData.java
index bd772b5..84f4bed 100644
--- a/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/StressTestData.java
+++ b/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/StressTestData.java
@@ -97,11 +97,13 @@ class StressTestData {
/**
* Creates the random generator.
*
+ * <p>It is recommended the seed is generated using {@link RandomSource#createSeed()}.</p>
+ *
+ * @param seed the seed (use {@code null} to automatically create a seed)
* @return the uniform random provider
*/
- UniformRandomProvider createRNG() {
- // Use a null seed to force seeding
- return RandomSource.create(randomSource, null, args);
+ UniformRandomProvider createRNG(byte[] seed) {
+ return RandomSource.create(randomSource, seed, args);
}
/**