{"library":"miller-rabin","title":"Miller-Rabin Primality Test","description":"The `miller-rabin` package provides an implementation of the probabilistic Miller-Rabin primality test algorithm for JavaScript. This algorithm efficiently determines if a given large number is likely prime, although it carries a small, exponentially decreasing chance of falsely identifying a composite number as prime (a 'strong liar'). The current stable version, 4.0.1, was last published 8 years ago, indicating a maintenance-only or abandoned status. It relies on the `bn.js` library for arbitrary-precision integer arithmetic, rather than native JavaScript `BigInt` introduced in later Node.js and browser versions. While functional, developers initiating new projects requiring primality testing might consider more recently updated alternatives that leverage native `BigInt` for potentially better performance and modern API integration. The package's release cadence is effectively non-existent, given its age.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install miller-rabin"],"cli":null},"imports":["import millerRabin from 'miller-rabin';","import MillerRabin from 'miller-rabin';","import BN from 'bn.js';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import millerRabin from 'miller-rabin';\nimport BN from 'bn.js';\n\n// Test a small number\nlet isPrimeSmall = millerRabin.test(new BN(7), 5); // 5 rounds\nconsole.log(`Is 7 prime? ${isPrimeSmall}`); // Expected: true\n\n// Test a larger number (e.g., a 256-bit number)\n// In a real application, this number would come from somewhere.\n// For demonstration, let's create a large prime-like number.\n// Using a known prime for demonstration purposes.\nconst largeNumberStr = '115792089237316195423570985008687907853269984665640564039457584007913129639937'; // A known large prime\nconst largeNumber = new BN(largeNumberStr, 10);\n\n// The number of rounds (iterations) affects the probability of error.\n// A higher number of rounds decreases the chance of a composite number being misidentified as prime.\nconst numberOfRounds = 64; \n\nconst testResult = millerRabin.test(largeNumber, numberOfRounds);\n\nconsole.log(`\nTesting: ${largeNumber.toString()}\nNumber of rounds: ${numberOfRounds}`);\nconsole.log(`Is it probably prime? ${testResult}`);\n\nconst compositeNumber = new BN('99999999999999999999999999999999999999999999999999999999999999999999999999991', 10); // A large composite\nconst testCompositeResult = millerRabin.test(compositeNumber, numberOfRounds);\nconsole.log(`\nTesting: ${compositeNumber.toString()}\nIs it probably prime? ${testCompositeResult}`); // Expected: false","lang":"javascript","description":"Demonstrates how to use `miller-rabin` to test both small and large numbers for primality using the `BN` class from its dependency `bn.js`, specifying the number of test rounds.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}