Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
850 B
1
Indexable
Never
// Function to check if a number is prime
function isPrime(num) {
    if (num <= 1) return false;
    if (num <= 3) return true;

    if (num % 2 === 0 || num % 3 === 0) return false;

    for (let i = 5; i * i <= num; i += 6) {
        if (num % i === 0 || num % (i + 2) === 0) {
            return false;
        }
    }

    return true;
}

// Function to generate a random 10-digit prime number
function generateRandom10DigitPrime() {
    while (true) {
        // Generate a random 10-digit number
        const randomNum = Math.floor(Math.random() * (9999999999 - 1000000000 + 1)) + 1000000000;

        // Check if the number is prime
        if (isPrime(randomNum)) {
            return randomNum;
        }
    }
}

// Example usage
const randomPrime = generateRandom10DigitPrime();
console.log(randomPrime);
Leave a Comment