Skip to content

Commit 570cbba

Browse files
taus88 RNG
1 parent e58f5d5 commit 570cbba

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

FindAFactor/_find_a_factor.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
#include <boost/dynamic_bitset.hpp>
5454
#include <boost/multiprecision/cpp_int.hpp>
55+
#include <boost/random.hpp>
5556

5657
#include <pybind11/pybind11.h>
5758
#include <pybind11/stl.h>
@@ -764,8 +765,8 @@ struct Factorizer {
764765
ForwardFn forwardFn;
765766

766767
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,
767-
size_t lm, const std::vector<size_t> &p, ForwardFn fn)
768-
: dis(0U, p.size() - 1U), wordDis(0ULL, -1ULL), toFactorSqr(tfsqr), toFactor(tf), toFactorSqrt(tfsqrt), batchRange(range), batchNumber(0U), batchOffset(nodeId * range),
768+
size_t lm, size_t bn, const std::vector<size_t> &p, ForwardFn fn)
769+
: dis(0U, p.size() - 1U), wordDis(0ULL, -1ULL), toFactorSqr(tfsqr), toFactor(tf), toFactorSqrt(tfsqrt), batchRange(range), batchNumber(bn), batchOffset(nodeId * range),
769770
batchTotal(nodeCount * range), wheelRadius(1U), wheelEntryCount(w), smoothBatchLimit(spl), batchSizeVariance(bsv), ladderMultiple(lm), isIncomplete(true), primes(p), forwardFn(fn)
770771
{
771772
for (size_t i = 0U; i < primes.size(); ++i) {
@@ -805,7 +806,7 @@ struct Factorizer {
805806
return 1U;
806807
}
807808

808-
BigInteger monteCarlo(std::mt19937_64& gen) {
809+
BigInteger monteCarlo(boost::random::taus88& gen) {
809810
// This function enters only once per thread.
810811
size_t batchPower = 0U;
811812

@@ -1108,18 +1109,20 @@ std::string find_a_factor(std::string toFactorStr, size_t method, size_t nodeCou
11081109
gearFactorizationPrimes.clear();
11091110

11101111
// Range per parallel node
1111-
const BigInteger nodeRange = (((backward(SMALLEST_WHEEL)(fullMaxBase) + nodeCount - 1U) / nodeCount) + wheelEntryCount - 1U) / wheelEntryCount;
1112+
const auto backwardFn = backward(SMALLEST_WHEEL);
1113+
const BigInteger nodeRange = (((backwardFn(fullMaxBase) + nodeCount - 1U) / nodeCount) + wheelEntryCount - 1U) / wheelEntryCount;
1114+
const size_t batchStart = ((size_t)backwardFn(trialDivisionLevel)) / wheelEntryCount;
11121115
// This manages the work of all threads.
11131116
Factorizer worker(toFactor * toFactor, toFactor, fullMaxBase,
11141117
nodeRange, nodeCount, nodeId,
11151118
wheelEntryCount, (size_t)(batchSizeMultiplier * smoothPrimes.size() * log(smoothPrimes.size())), batchSizeVariance,
1116-
ladderMultiple, smoothPrimes, forward(SMALLEST_WHEEL));
1119+
ladderMultiple, batchStart, smoothPrimes, forward(SMALLEST_WHEEL));
11171120
// Square of count of smooth primes, for FACTOR_FINDER batch multiplier base unit, was suggested by Lyra (OpenAI GPT)
11181121

11191122
std::vector<std::future<BigInteger>> futures;
11201123
futures.reserve(CpuCount);
11211124

1122-
std::vector<std::mt19937_64> gen;
1125+
std::vector<boost::random::taus88> gen;
11231126
if (isFactorFinder) {
11241127
std::default_random_engine rng{};
11251128
gen.reserve(CpuCount);

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.1"
11+
version = "4.7.2"
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.1',
43+
version='4.7.2',
4444
author='Dan Strano',
4545
author_email='stranoj@gmail.com',
4646
description='Find any nontrivial factor of a number',

0 commit comments

Comments
 (0)