File tree Expand file tree Collapse file tree 5 files changed +13
-16
lines changed
main/java/de/tilman_neumann/jml
test/java/de/tilman_neumann/jml/random Expand file tree Collapse file tree 5 files changed +13
-16
lines changed Original file line number Diff line number Diff line change 11/*
22 * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project.
3- * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de
3+ * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de
44 *
55 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
66 * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
@@ -46,7 +46,7 @@ public class PollardRhoBrentMontgomery64 extends FactorAlgorithm {
4646 private static final Logger LOG = LogManager .getLogger (PollardRhoBrentMontgomery64 .class );
4747 private static final boolean DEBUG = false ;
4848
49- private static final Rng RNG = new Rng ();
49+ private static final Rng RNG = new Rng (); // the numbers produced by java.util.Random.nextLong(bound) have better quality, but that needs Java 17
5050
5151 // The reducer R is 2^64, but the only constant still required is the half of it.
5252 private static final long R_HALF = 1L << 63 ;
Original file line number Diff line number Diff line change 11/*
22 * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project.
3- * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de
3+ * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de
44 *
55 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
66 * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
@@ -50,7 +50,7 @@ public class PollardRhoBrentMontgomery64MH extends FactorAlgorithm {
5050 private static final Logger LOG = LogManager .getLogger (PollardRhoBrentMontgomery64MH .class );
5151 private static final boolean DEBUG = false ;
5252
53- private static final Rng RNG = new Rng ();
53+ private static final Rng RNG = new Rng (); // the numbers produced by java.util.Random.nextLong(bound) have better quality, but that needs Java 17
5454
5555 // The reducer R is 2^64, but the only constant still required is the half of it.
5656 private static final long R_HALF = 1L << 63 ;
Original file line number Diff line number Diff line change 11/*
22 * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project.
3- * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de
3+ * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de
44 *
55 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
66 * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
@@ -50,7 +50,7 @@ public class PollardRhoBrentMontgomery64MHInlined extends FactorAlgorithm {
5050 private static final Logger LOG = LogManager .getLogger (PollardRhoBrentMontgomery64MHInlined .class );
5151 private static final boolean DEBUG = false ;
5252
53- private static final Rng RNG = new Rng ();
53+ private static final Rng RNG = new Rng (); // the numbers produced by java.util.Random.nextLong(bound) have better quality, but that needs Java 17
5454
5555 // The reducer R is 2^64, but the only constant still required is the half of it.
5656 private static final long R_HALF = 1L << 63 ;
Original file line number Diff line number Diff line change @@ -57,15 +57,15 @@ public Rng(long seed) {
5757 * @return random int in the desired range
5858 */
5959 public int nextInt (int minValue , int maxValue ) {
60- int diff = maxValue - minValue ;
61- if (diff < 1 ) throw new IllegalArgumentException ("maxValue=" + maxValue + " must be bigger than minValue=" + minValue );
62- int rand = nextInt (diff ); // 0...(diff-1)
63- return minValue + rand ;
60+ return minValue + nextInt (maxValue - minValue );
6461 }
6562
6663 /**
6764 * Creates a random long from the uniform distribution U[0, maxValue-1].
6865 * The only requirement is maxValue > 0.
66+ *
67+ * The numbers produced by java.util.Random.nextLong(bound) have better quality, but that needs Java 17.
68+ *
6969 * @param maxValue
7070 * @return random long in the desired range
7171 */
@@ -94,10 +94,7 @@ public long nextLong(long maxValue) {
9494 * @return random long in the desired range
9595 */
9696 public long nextLong (long minValue , long maxValue ) {
97- long diff = maxValue - minValue ;
98- if (diff < 1 ) throw new IllegalArgumentException ("maxValue=" + maxValue + " must be bigger than minValue=" + minValue );
99- long rand = nextLong (diff ); // 0...(diff-1)
100- return minValue + rand ;
97+ return minValue + nextLong (maxValue - minValue );
10198 }
10299
103100 /**
Original file line number Diff line number Diff line change @@ -123,12 +123,12 @@ private static void testNextIntWithLowerUpperBound() {
123123 /*
124124 if (TEST_SLOW) {
125125 for (int i=0; i<NCOUNT; i++) {
126- secureRandom.nextInt(LOWER_INT, UPPER_INT); // XXX which Java version is required ?
126+ secureRandom.nextInt(LOWER_INT, UPPER_INT); // needs Java 17
127127 }
128128 LOG.debug("SecureRandom.nextInt(" + LOWER_INT + ", " + UPPER_INT + ") took " + timer.capture() + " ms");
129129 }
130130 for (int i=0; i<NCOUNT; i++) {
131- random.nextInt(LOWER_INT, UPPER_INT); // XXX which Java version is required ?
131+ random.nextInt(LOWER_INT, UPPER_INT); // needs Java 17
132132 }
133133 LOG.debug("Random.nextInt(" + LOWER_INT + ", " + UPPER_INT + ") took " + timer.capture() + " ms");
134134 */
You can’t perform that action at this time.
0 commit comments