'How two processor will share same function

I have this function here that is factoring a number n. Right now I am using two processors to run the same function and as soon as one of the processors get a result the process ends. I was reading this article (page 3): http://koclab.cs.ucsb.edu/teaching/ecc/project/2015Projects/Christensen+Johnsrud.pdf,

It's saying I can improve what I have by only having X be random but the rest of the function should be shared by both processes.

"This can be improved to a factor of M by letting the sequences generated by the different processors collide with each other. To be more specific, the M processors choose it’s own independently starting point X0, but they all share the same iterating function f to compute the next Xi points. As a result of this, if two sequences from different processors collide then the two sequences will be identical"

I am lost in how to do this. How can I improve my code to make this happen? I thought if I created a function separated that calculates (x**2 + c) % n and send c as a parameter then I would get. But when I do that both processors returns n

def rho(p):

        n, process = p
        x = random.randrange(1, n-1)
        x2 = x
        gcd = 1
        c = random.randrange(1, n-1)

        while gcd == 1:
            x = (x**2 + c) % n
            x2 = (x2**2 + c) % n
            x2 = (x2**2 + c) % n
            gcd = math.gcd(abs(x - x2), n)

        
        print("Factor was found from "+process+" and is ", gcd)
        return gcd


if __name__ == "__main__":
   
    n = 10403
    with Pool() as pool:
        for result in pool.imap_unordered(
                rho, ((n, "process 1"), (n, "process 2"))
        ):
            print("Result I got:", result)
            break  # <-- I don't want other results, so break



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source