I am trying to write a program in Python to compute a sequence of pseudorandom numbers using the lagged Fibonacci method. I want to generate 2000 numbers in the range (0, 2**32) and then plot x_i against x_i-1. I have:
def lag(s):
for i in range(k):
if i is 0:
out = (s[j-1] + s[k-1]) % m
elif 0 < i < k - 1:
s[i] = s[i+1]
else:
s[i] = out
print(s[i])
j, k, m = 7, 10, 2**32
X=[1]
for n in range(2000):
X.append(lag(X[-1]))
y = X[:]
y.append(y[0])
del y[0]
import matplotlib.pyplot as plt
plt.plot(X, y, '.')
When I run the program I get the error
out = (s[j-1] + s[k-1]) % m
TypeError: 'int' object is not subscriptable
I'm not sure what this error means or how to fix it. Can anyone help?
Aucun commentaire:
Enregistrer un commentaire