Last active
August 29, 2015 14:00
-
-
Save TimSC/6397f4fa6dd5d632611f to your computer and use it in GitHub Desktop.
Find prime numbers. Good for giving the CPU some exercise!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random, math | |
def FindPrimes(lowLimit, highLimit): | |
cand = list(range(lowLimit, highLimit)) | |
for i in range(2,lowLimit): | |
current = i * int(math.floor(lowLimit / i)) | |
while current < highLimit: | |
if current in cand: | |
cand.remove(current) | |
current += i | |
return cand | |
if __name__=="__main__": | |
while True: | |
l1 = random.randint(1000000,10000000) | |
l2 = l1 + 1000 | |
cand = FindPrimes(l1, l2) | |
print (l1, l2, cand) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment