Skip to content

Commit

Permalink
Don't use uniform_smallint
Browse files Browse the repository at this point in the history
  • Loading branch information
WrathfulSpatula committed Jan 18, 2025
1 parent 6b66235 commit 3618504
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions FindAFactor/_find_a_factor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,7 @@ inline BigInteger modExp(BigInteger base, BigInteger exp, const BigInteger &mod)

struct Factorizer {
std::mutex batchMutex;
boost::uniform_smallint<size_t> dis;
std::uniform_int_distribution<size_t> wordDis;
std::uniform_int_distribution<size_t> dis;
BigInteger toFactorSqr;
BigInteger toFactor;
BigInteger toFactorSqrt;
Expand All @@ -774,8 +773,8 @@ struct Factorizer {

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,
size_t lm, size_t bn, const std::vector<size_t> &p, ForwardFn fn)
: dis(0U, p.size() - 1U), wordDis(0ULL, -1ULL), toFactorSqr(tfsqr), toFactor(tf), toFactorSqrt(tfsqrt), batchRange(range), batchNumber(bn), batchOffset(nodeId * range),
batchTotal(nodeCount * range), wheelRadius(1U), wheelEntryCount(w), smoothBatchLimit(spl), batchSizeVariance(bsv), ladderMultiple(lm), isIncomplete(true), primes(p), forwardFn(fn)
: dis(0ULL, -1ULL), toFactorSqr(tfsqr), toFactor(tf), toFactorSqrt(tfsqrt), batchRange(range), batchNumber(bn), batchOffset(nodeId * range), batchTotal(nodeCount * range),
wheelRadius(1U), wheelEntryCount(w), smoothBatchLimit(spl), batchSizeVariance(bsv), ladderMultiple(lm), isIncomplete(true), primes(p), forwardFn(fn)
{
for (size_t i = 0U; i < primes.size(); ++i) {
const size_t& p = primes[i];
Expand Down Expand Up @@ -824,7 +823,7 @@ struct Factorizer {
BigInteger perfectSquare = 1U;
std::vector<size_t> fv(primes.size(), 0);
while (perfectSquare < toFactor) {
BigInteger n = forwardFn(((batchOffset + (wordDis(gen) % batchRange)) * wheelEntryCount) + (wordDis(gen) % wheelEntryCount));
BigInteger n = forwardFn(((batchOffset + (dis(gen) % batchRange)) * wheelEntryCount) + (dis(gen) % wheelEntryCount));
const std::vector<size_t> pfv = factorizationVector(&n);
if (!pfv.size()) {
continue;
Expand All @@ -845,7 +844,7 @@ struct Factorizer {
size_t batchPart = 0U;
while (perfectSquare < toFactorSqr) {
// Pick a random prime ordinal.
const size_t pi = dis(gen);
const size_t pi = dis(gen) % primes.size();
// Retrieve the square prime for the ordinal.
const size_t& rsp = sqrPrimes[pi];
size_t& fvc = fv[pi];
Expand Down Expand Up @@ -918,7 +917,7 @@ struct Factorizer {
size_t pi;
do {
// Loop until the population is nonzero (with guaranteed even parity).
pi = dis(gen);
pi = dis(gen) % primes.size();
} while (!fv[pi]);

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

// Multiply the random smooth perfect square by the squares of smooth primes.
while (perfectSquare < toFactor) {
const size_t pi = dis(gen);
const size_t pi = dis(gen) % primes.size();
perfectSquare *= sqrPrimes[pi];
++(fv[pi]);
}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "FindAFactor"
version = "4.7.3"
version = "4.7.4"
requires-python = ">=3.8"
description = "Find any nontrivial factor of a number"
readme = {file = "README.txt", content-type = "text/markdown"}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def build_extension(self, ext):

setup(
name='FindAFactor',
version='4.7.3',
version='4.7.4',
author='Dan Strano',
author_email='[email protected]',
description='Find any nontrivial factor of a number',
Expand Down

0 comments on commit 3618504

Please sign in to comment.