Skip to content

Commit

Permalink
Merge pull request #343 from cicirello/refactor-triples
Browse files Browse the repository at this point in the history
Refactored nextIntTriple, and prepare release 4.2.0
  • Loading branch information
cicirello authored Aug 16, 2024
2 parents 7f5a1d8 + 0d705a0 commit 5a641ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
21 changes: 7 additions & 14 deletions src/main/java/org/cicirello/math/rand/RandomIndexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 5a641ac

Please sign in to comment.