diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c5b7c7..6950d49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] - 2024-06-08 +## [Unreleased] - 2024-08-16 ### Added @@ -23,6 +23,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Other +## [4.2.0] - 2024-08-16 + +### Changed +* Refactored nextIntTriple to simplify logic, based on suggestion from anonymous reviewer of journal article submission. No impact on performance of array version of method, but code easier to read. Version that returns a record a few nanoseconds faster per call as well as easier to read. + + ## [4.1.0] - 2024-06-08 ### Changed diff --git a/src/main/java/org/cicirello/math/rand/RandomIndexer.java b/src/main/java/org/cicirello/math/rand/RandomIndexer.java index 00e2000..697f511 100644 --- a/src/main/java/org/cicirello/math/rand/RandomIndexer.java +++ b/src/main/java/org/cicirello/math/rand/RandomIndexer.java @@ -498,18 +498,14 @@ public static int[] nextIntTriple(int n, int[] result, RandomGenerator gen) { result[0] = nextInt(n, gen); result[1] = nextInt(n - 1, gen); result[2] = nextInt(n - 2, gen); + if (result[2] == result[1]) { + result[2] = n - 2; + } if (result[1] == result[0]) { result[1] = n - 1; - if (result[2] == result[0]) { - result[2] = n - 2; - } - } else { - if (result[2] == result[1]) { - result[2] = n - 2; - } - if (result[2] == result[0]) { - result[2] = n - 1; - } + } + if (result[2] == result[0]) { + result[2] = n - 1; } return result; } @@ -556,13 +552,10 @@ public static IndexTriple nextIntTriple(int n, RandomGenerator gen) { final int i = nextInt(n, gen); final int j = nextInt(n - 1, gen); int k = nextInt(n - 2, gen); - if (j == i) { - return new IndexTriple(i, n - 1, k == i ? n - 2 : k); - } if (k == j) { k = n - 2; } - return new IndexTriple(i, j, k == i ? n - 1 : k); + return new IndexTriple(i, j == i ? n - 1 : j, k == i ? n - 1 : k); } /**