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 0bda14c Add stress test option to combine bits with a system identity hash code. 0bda14c is described below commit 0bda14cc5fc04155f8d1d2c4eeb8d1e1dd6160a3 Author: aherbert <aherb...@apache.org> AuthorDate: Mon Jun 3 11:38:09 2019 +0100 Add stress test option to combine bits with a system identity hash code. --- .../commons/rng/examples/stress/RNGUtils.java | 28 ++++++++++++++++++++++ .../rng/examples/stress/StressTestCommand.java | 16 ++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/RNGUtils.java b/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/RNGUtils.java index aac26fb..a7f77d5 100644 --- a/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/RNGUtils.java +++ b/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/RNGUtils.java @@ -79,6 +79,34 @@ final class RNGUtils { } /** + * Wrap the random generator with an {@link IntProvider} that will combine the bits + * using a {@code xor} operation with a generated hash code. + * + * <pre>{@code + * System.identityHashCode(new Object()) ^ rng.nextInt() + * }</pre> + * + * Note: This generator will be slow. + * + * @param rng The random generator. + * @return the hash code combined random generator. + * @see System#identityHashCode(Object) + */ + static UniformRandomProvider createHashCodeIntProvider(final UniformRandomProvider rng) { + return new IntProvider() { + @Override + public int next() { + return System.identityHashCode(new Object()) ^ rng.nextInt(); + } + + @Override + public String toString() { + return "HashCode ^ " + rng.toString(); + } + }; + } + + /** * Parses the argument into an object suitable for the RandomSource constructor. Supports: * * <ul> 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 016d3a4..a34721e 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 @@ -121,13 +121,24 @@ class StressTestCommand implements Callable<Void> { "Valid values: BIG_ENDIAN, LITTLE_ENDIAN."}) private ByteOrder byteOrder = ByteOrder.nativeOrder(); - /** The output byte order of the binary data. */ + /** Flag to indicate the output should be bit-reversed. */ @Option(names = {"-r", "--reverse-bits"}, description = {"Reverse the bits in the data (default: ${DEFAULT-VALUE}).", "Note: Generators may fail tests for a reverse sequence " + "when passing using the standard sequence."}) private boolean reverseBits; + /** + * Flag to indicate the output should be combined with a hashcode from a new object. + * This is a method used in the {@link org.apache.commons.rng.simple.internal.SeedFactory SeedFactory}. + * + * @see System#identityHashCode(Object) + */ + @Option(names = {"--hashcode"}, + description = {"Combine the bits with a hashcode (default: ${DEFAULT-VALUE}).", + "System.identityHashCode(new Object()) ^ rng.nextInt()."}) + private boolean xorHashCode; + /** The flag to indicate a dry run. */ @Option(names = {"--dry-run"}, description = "Perform a dry run where the generators and output files are created " + @@ -397,6 +408,9 @@ class StressTestCommand implements Callable<Void> { if (reverseBits) { rng = RNGUtils.createReverseBitsIntProvider(rng); } + if (xorHashCode) { + rng = RNGUtils.createHashCodeIntProvider(rng); + } // Run the test final Runnable r = new StressTestTask(testData.getRandomSource(), rng, output, command, this, progressTracker);