29 lines
785 B
Python
29 lines
785 B
Python
|
#num = (1<<127) | 1
|
||
|
from time import time_ns
|
||
|
n = 3 #max random number will be (2^n)
|
||
|
|
||
|
def randomNumber(maxN):
|
||
|
num = time_ns()
|
||
|
num = int(format(num, '0127b'), base=2)
|
||
|
array=[]
|
||
|
for i in range(16000):
|
||
|
array.append(num & 1)
|
||
|
new = (num ^ (num >> 1) ^ (num >> 2)^(num >> 7)) & 1
|
||
|
num = (num >> 1) | (new << 127)
|
||
|
|
||
|
i=0
|
||
|
while True:
|
||
|
j = "".join([str(x) for x in array[-15-i:-1-i]])
|
||
|
index = int(j,2)
|
||
|
if index < len(array):
|
||
|
break
|
||
|
else:
|
||
|
i+=1
|
||
|
|
||
|
rnum = int("".join([str(x) for x in array[index-maxN:index]]),2)
|
||
|
return rnum+1
|
||
|
|
||
|
if __name__=="__main__":
|
||
|
paper_num=randomNumber(n)
|
||
|
question_num=randomNumber(n)
|
||
|
print(f"Next exercise is question {question_num} from paper {paper_num}")
|