{"record":{"id":"97e5e18ff8b97596","repo":"TheAlgorithms/Python","slug":"warning-upper-bound-of-deterministic-test-is-exce","errorCode":null,"errorMessage":"Warning: upper bound of deterministic test is exceeded. Pass allow_probable=True to allow probabilistic test. A return value of True indicates a probable prime.","messagePattern":"Warning: upper bound of deterministic test is exceeded\\. Pass allow_probable=True to allow probabilistic test\\. A return value of True indicates a probable prime\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"ciphers/deterministic_miller_rabin.py","lineNumber":38,"sourceCode":"    allow_probable: bool, default False\n        Whether or not to test n above the upper bound of the deterministic test.\n\n    Raises\n    ------\n    ValueError\n\n    Reference\n    ---------\n    https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test\n    \"\"\"\n    if n == 2:\n        return True\n    if not n % 2 or n < 2:\n        return False\n    if n > 5 and n % 10 not in (1, 3, 7, 9):  # can quickly check last digit\n        return False\n    if n > 3_317_044_064_679_887_385_961_981 and not allow_probable:\n        raise ValueError(\n            \"Warning: upper bound of deterministic test is exceeded. \"\n            \"Pass allow_probable=True to allow probabilistic test. \"\n            \"A return value of True indicates a probable prime.\"\n        )\n    # array bounds provided by analysis\n    bounds = [\n        2_047,\n        1_373_653,\n        25_326_001,\n        3_215_031_751,\n        2_152_302_898_747,\n        3_474_749_660_383,\n        341_550_071_728_321,\n        1,\n        3_825_123_056_546_413_051,\n        1,\n        1,\n        318_665_857_834_031_151_167_461,","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/ciphers/deterministic_miller_rabin.py#L20-L56","documentation":"Raised by the deterministic Miller-Rabin primality test in ciphers/deterministic_miller_rabin.py when n exceeds 3,317,044,064,679,887,385,961,981 — the largest range for which the fixed witness set is proven deterministic. Without allow_probable=True the library refuses to give a possibly-wrong 'prime' answer.","triggerScenarios":"Calling miller_rabin(n) (or the module's test function) with n above ~3.3e24 and the default allow_probable=False; primality checks on 256-bit-plus cryptographic candidates.","commonSituations":"RSA/diffie-hellman key generation with modern key sizes (2048+ bit candidates); benchmarking the test with very large numbers; upgrading inputs from 64-bit experiments to big-int territory.","solutions":["Pass allow_probable=True if a probabilistic answer is acceptable for your use case","Use a primality test designed for arbitrary sizes (e.g. stdlib-free sympy.isprime or your own random-witness Miller-Rabin with enough rounds)","Keep n at or below the bound for a guaranteed deterministic result"],"exampleFix":"# before\nis_prime = miller_rabin(huge_number)\n\n# after\nis_prime = miller_rabin(huge_number, allow_probable=True)  # probabilistic for n > bound","handlingStrategy":"validation","validationCode":"DETERMINISTIC_BOUND = 3_317_044_064_679_887_385_961_981\nallow_probable = n > DETERMINISTIC_BOUND  # opt in only when required","typeGuard":null,"tryCatchPattern":"try:\n    prime = miller_rabin(n)\nexcept ValueError:\n    prime = miller_rabin(n, allow_probable=True)  # acceptable for crypto-size candidates","preventionTips":["Know the deterministic bound (~3.3e24) before testing big candidates","Pass allow_probable=True deliberately for cryptographic sizes","For guaranteed results, use a proven-deterministic method (e.g. ECPP or AKS) instead"],"tags":["primality","miller-rabin","big-int","cryptography"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}