from time import time_ns n = 3 #max random number will be (2^n) def randomNumber(maxN): allen = time_ns() allen = int(format(allen, '0127b'), base=2) array=[] for i in range(16000): array.append(allen & 1) new = (allen ^ (allen >> 1) ^ (allen >> 2)^(allen >> 7)) & 1 allen = (allen >> 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}")