Skip to content

Commit

Permalink
factor: rename input parameter
Browse files Browse the repository at this point in the history
Closes: uutils#5883
  • Loading branch information
kralo committed Jan 28, 2024
1 parent 6e09cba commit 9adceb4
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/uu/factor/src/rho.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ use std::cmp::{max, min};

use crate::numeric::*;

pub(crate) fn find_divisor<A: Arithmetic>(n: A) -> u64 {
#![allow(clippy::many_single_char_names)]
pub(crate) fn find_divisor<A: Arithmetic>(input: A) -> u64 {
let mut rand = {
let range = Uniform::new(1, n.modulus());
let range = Uniform::new(1, input.modulus());
let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap();
move || n.to_mod(range.sample(&mut rng))
move || input.to_mod(range.sample(&mut rng))
};

let quadratic = |a, b| move |x| n.add(n.mul(a, n.mul(x, x)), b);
let quadratic = |a, b| move |x| input.add(input.mul(a, input.mul(x, x)), b);

loop {
let f = quadratic(rand(), rand());
Expand All @@ -29,11 +28,11 @@ pub(crate) fn find_divisor<A: Arithmetic>(n: A) -> u64 {
x = f(x);
y = f(f(y));
let d = {
let _x = n.to_u64(x);
let _y = n.to_u64(y);
gcd(n.modulus(), max(_x, _y) - min(_x, _y))
let _x = input.to_u64(x);
let _y = input.to_u64(y);
gcd(input.modulus(), max(_x, _y) - min(_x, _y))
};
if d == n.modulus() {
if d == input.modulus() {
// Failure, retry with a different quadratic
break;
} else if d > 1 {
Expand Down

0 comments on commit 9adceb4

Please sign in to comment.