Skip to content

Instantly share code, notes, and snippets.

@TimSC
Last active August 29, 2015 14:00
Show Gist options
  • Save TimSC/6397f4fa6dd5d632611f to your computer and use it in GitHub Desktop.
Save TimSC/6397f4fa6dd5d632611f to your computer and use it in GitHub Desktop.
Find prime numbers. Good for giving the CPU some exercise!
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