I tried to perform the following code using python:
My code is:
#UNIFORM RANDOM SAMPLING
import numpy as np #library needed for numerical calculations
import matplotlib.pyplot as plt #library needed for plotting purposes
from time import process_time #function needed for checking CPU time
from scipy.stats import chisquare #function needed for chi square test
#*******************************************************************************
i=np.uintc(987654321) #unsigned int variable i with seed 987654321
r=2**30 #range of the sequence
t1_start=process_time() #process start time
for count in range(r): #for cycle over expected period and update i
i=np.uintc(i*663608941)
t1_stop=process_time() #process stop time
print("\nLoop stopped at the element:", i, ".\n")
print("Is this the last element of the series? 1 for YES other numbers for NO", i/987654321,".\n")
print("The CPU time needed in order to take to go throught the whole sequence is", t1_stop-t1_start, "seconds.\n")
Meanwhile the output:
As you can see, the programm woks, but is not very optimized ( almost 1 hour of run).
How can I optimize it and obtain the desired output in many seconds?
Aucun commentaire:
Enregistrer un commentaire