-
Notifications
You must be signed in to change notification settings - Fork 0
/
Primes.py
55 lines (43 loc) · 1.53 KB
/
Primes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import time
def isPrime(value):
if value > 1: # every prime value is bigger than 1
for divisor in range(2, value): # every prime value is dividable by 1
if value % divisor == 0:
return True
return False
def getRandomPrime(primes):
return primes.getFirstLower(primes.getFirstHigher((int(time.time())) % 1000) *
primes.getFirstLower((int(time.time())) % 1000))
class Primes:
def __init__(self):
self.higher_prime = None
self.lower_prime = None
self.prime = None
def getCalculatedPrimeValue(self, option):
if option == 'higher':
if self.higher_prime is not None:
return int(self.higher_prime)
else:
return None
elif option == 'lower':
if self.lower_prime is not None:
return int(self.lower_prime)
else:
return None
else:
if self.prime is not None:
return int(self.prime)
else:
return None
def getFirstHigher(self, seed):
local_var = seed
while isPrime(local_var) or local_var == seed:
local_var = local_var + 1
self.higher_prime = local_var
return int(self.higher_prime)
def getFirstLower(self, seed):
local_var = seed
while isPrime(local_var) or local_var == seed:
local_var = local_var - 1
self.lower_prime = local_var
return int(self.lower_prime)