-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathno_multithread.py
executable file
·44 lines (35 loc) · 1.03 KB
/
no_multithread.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
#! /usr/bin/python3
import os
import sys
import time
import PyMultiThread
def sqrt(inputNum):
return int(inputNum ** 0.5)
# Returns a random int with length of x bytes.
def randNum(length=1):
return int.from_bytes(os.urandom(length),'big')
# Returns True if Num2 is a factor of Num1
def divTest(num1,num2):
return bool(num1 % num2)
# Returns True if inputNum is a Prime
def primeTest(inputNum):
result = bool(inputNum & 1)
if result:
# 2nd Level Multiprocessing Starts Here
for i in range((sqrt(inputNum)-1)>>1):
if not divTest(inputNum,(i<<1)+3):
result = False
break
return result
# Returns a random prime number with length of x bytes.
def randomPrime(length=1):
result = randNum(length) | 1
# 1st Level Multiprocessing Starts Here
while not primeTest(result):
result = randNum(length)
return result
def main(args):
for i in range(int(args[0])):
print(randomPrime(int(args[1])))
if __name__ == '__main__':
main(sys.argv[1:])