Skip to content

Commit 3618504

Browse files
Don't use uniform_smallint
1 parent 6b66235 commit 3618504

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

FindAFactor/_find_a_factor.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,7 @@ inline BigInteger modExp(BigInteger base, BigInteger exp, const BigInteger &mod)
753753

754754
struct Factorizer {
755755
std::mutex batchMutex;
756-
boost::uniform_smallint<size_t> dis;
757-
std::uniform_int_distribution<size_t> wordDis;
756+
std::uniform_int_distribution<size_t> dis;
758757
BigInteger toFactorSqr;
759758
BigInteger toFactor;
760759
BigInteger toFactorSqrt;
@@ -774,8 +773,8 @@ struct Factorizer {
774773

775774
Factorizer(const BigInteger &tfsqr, const BigInteger &tf, const BigInteger &tfsqrt, const BigInteger &range, size_t nodeCount, size_t nodeId, size_t w, size_t spl, size_t bsv,
776775
size_t lm, size_t bn, const std::vector<size_t> &p, ForwardFn fn)
777-
: dis(0U, p.size() - 1U), wordDis(0ULL, -1ULL), toFactorSqr(tfsqr), toFactor(tf), toFactorSqrt(tfsqrt), batchRange(range), batchNumber(bn), batchOffset(nodeId * range),
778-
batchTotal(nodeCount * range), wheelRadius(1U), wheelEntryCount(w), smoothBatchLimit(spl), batchSizeVariance(bsv), ladderMultiple(lm), isIncomplete(true), primes(p), forwardFn(fn)
776+
: dis(0ULL, -1ULL), toFactorSqr(tfsqr), toFactor(tf), toFactorSqrt(tfsqrt), batchRange(range), batchNumber(bn), batchOffset(nodeId * range), batchTotal(nodeCount * range),
777+
wheelRadius(1U), wheelEntryCount(w), smoothBatchLimit(spl), batchSizeVariance(bsv), ladderMultiple(lm), isIncomplete(true), primes(p), forwardFn(fn)
779778
{
780779
for (size_t i = 0U; i < primes.size(); ++i) {
781780
const size_t& p = primes[i];
@@ -824,7 +823,7 @@ struct Factorizer {
824823
BigInteger perfectSquare = 1U;
825824
std::vector<size_t> fv(primes.size(), 0);
826825
while (perfectSquare < toFactor) {
827-
BigInteger n = forwardFn(((batchOffset + (wordDis(gen) % batchRange)) * wheelEntryCount) + (wordDis(gen) % wheelEntryCount));
826+
BigInteger n = forwardFn(((batchOffset + (dis(gen) % batchRange)) * wheelEntryCount) + (dis(gen) % wheelEntryCount));
828827
const std::vector<size_t> pfv = factorizationVector(&n);
829828
if (!pfv.size()) {
830829
continue;
@@ -845,7 +844,7 @@ struct Factorizer {
845844
size_t batchPart = 0U;
846845
while (perfectSquare < toFactorSqr) {
847846
// Pick a random prime ordinal.
848-
const size_t pi = dis(gen);
847+
const size_t pi = dis(gen) % primes.size();
849848
// Retrieve the square prime for the ordinal.
850849
const size_t& rsp = sqrPrimes[pi];
851850
size_t& fvc = fv[pi];
@@ -918,7 +917,7 @@ struct Factorizer {
918917
size_t pi;
919918
do {
920919
// Loop until the population is nonzero (with guaranteed even parity).
921-
pi = dis(gen);
920+
pi = dis(gen) % primes.size();
922921
} while (!fv[pi]);
923922

924923
perfectSquare /= sqrPrimes[pi];
@@ -941,7 +940,7 @@ struct Factorizer {
941940

942941
// Multiply the random smooth perfect square by the squares of smooth primes.
943942
while (perfectSquare < toFactor) {
944-
const size_t pi = dis(gen);
943+
const size_t pi = dis(gen) % primes.size();
945944
perfectSquare *= sqrPrimes[pi];
946945
++(fv[pi]);
947946
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"
88

99
[project]
1010
name = "FindAFactor"
11-
version = "4.7.3"
11+
version = "4.7.4"
1212
requires-python = ">=3.8"
1313
description = "Find any nontrivial factor of a number"
1414
readme = {file = "README.txt", content-type = "text/markdown"}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def build_extension(self, ext):
4040

4141
setup(
4242
name='FindAFactor',
43-
version='4.7.3',
43+
version='4.7.4',
4444
author='Dan Strano',
4545
author_email='stranoj@gmail.com',
4646
description='Find any nontrivial factor of a number',

0 commit comments

Comments
 (0)