Back to Code List
python

Primality Test

A simple function that determines a number's primality by testing it a given amount of times.

   main.py

import random

def primality_test(numToTest, numTimes):
    i = 0
    while i<numTimes:
        a = random.randint(1,numToTest-1)
        if (a**(numToTest-1)%numToTest == a%numToTest):
            return False
        i+=1
    return True