v1.1
Generate random prime numbers with Deno and the Miller-Rabin test.
Repository
Current version released
4 years ago
Dependencies
deno.land/x
Versions
Deno Random Prime Numbers
Description
Generate random prime numbers with a desired bit-length and an optional number of tests.
Usage
Generate a Random Prime Number
randomPrime(bitlength, tests)
Where:
randomPrime()
returns abigint
.bitlength
is anumber
.tests
is an optionalnumber
with a default value of 10.
Example:
import { randomPrime } from "https://deno.land/x/random_prime/mod.ts";
// Generate a random 1024-bit prime number with 10 primality tests
var prime: bigint = randomPrime(1024)
// Generate a random 2048-bit prime number with 20 primality tests
var prime: bigint = randomPrime(2048, 20)
Test if a BigInt is a Prime Number with Miller-Rabin
isProbablePrime(candidate, tests)
Where:
isProbablePrime()
returns aboolean
.candidate
is abigint
.tests
is an optionalnumber
with a default value of 10.
Example:
import { isProbablePrime } from "https://deno.land/x/random_prime/mod.ts";
// Have a number to test for primality
const candidate: bigint = 167n;
// Check if candidate is a probable prime with 10 primality tests
isProbablePrime(candidate) ? console.log("probable prime") : console.log("composite");
License
MIT License.