MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / rand_fn

Function rand_fn

maths/pollard_rho.py:58–74  ·  view source on GitHub ↗

Returns a pseudorandom value modulo ``modulus`` based on the input ``value`` and attempt-specific ``step`` size. >>> rand_fn(0, 0, 0) Traceback (most recent call last): ... ZeroDivisionError: integer division or modulo by zero >>> rand_fn

(value: int, step: int, modulus: int)

Source from the content-addressed store, hash-verified

56 # To make retries easier, we will instead use ``f(x) = (x**2 + C) % num``
57 # where ``C`` is a value that we can modify between each attempt.
58 def rand_fn(value: int, step: int, modulus: int) -> int:
59 """
60 Returns a pseudorandom value modulo ``modulus`` based on the
61 input ``value`` and attempt-specific ``step`` size.
62
63 >>> rand_fn(0, 0, 0)
64 Traceback (most recent call last):
65 ...
66 ZeroDivisionError: integer division or modulo by zero
67 >>> rand_fn(1, 2, 3)
68 0
69 >>> rand_fn(0, 10, 7)
70 3
71 >>> rand_fn(1234, 1, 17)
72 16
73 """
74 return (pow(value, 2) + step) % modulus
75
76 for _ in range(attempts):
77 # These track the position within the cycle detection logic.

Callers 1

pollard_rhoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected