Here is some python code for a random walk simulation. The code allows you to set the particle's initial position however I want the particle to be released specifically from the edge of a "box"/the array, before it does its random walk.
import numpy as np
import random
import matplotlib.pyplot as plt
np.random.seed(25)
x_init = 0
y_init = 0
x = [x_init]
y = [y_init]
n = 1000
x_array = np.random.randint(-1,2,n)
y_array = np.random.randint(-1,2,n)
for i in range(n):
# Update position
x_init += x_array[i]
y_init += y_array[i]
# Append new position
x.append(x_init)
y.append(y_init)
plt.plot(x,y)
plt.show()
I have tried manually setting the axis however inevitably this just reproduces the same random walk and cuts off anything not in the barriers of the axis - rather than creating the random walk from that point.
import numpy as np
import random
import matplotlib.pyplot as plt
np.random.seed(25)
x_init = 0
y_init = 0
x = [x_init]
y = [y_init]
n = 1000
x_array = np.random.randint(-1,2,n)
y_array = np.random.randint(-1,2,n)
for i in range(n):
# Update position
x_init += x_array[i]
y_init += y_array[i]
# Append new position
x.append(x_init)
y.append(y_init)
plt.axis([0,10,0,10]);
plt.plot(x,y)
plt.show()
How would I fix the code so that i can set the initial position to be from the edge of the box/array?