
# rWalk2D.py

import random
import matplotlib.pyplot as plt


def rWalk2D(n):
  x = 0
  xs = [x]
  y = 0
  ys = [y]
  for _ in range(1, n+1):
    x += random.choice([-1,0,1])
    xs.append(x)
    y += random.choice([-1,0,1])
    ys.append(y)
  return xs, ys

xs, ys = rWalk2D(1000)
plt.plot(xs, ys, 'r-')
plt.axhline(0)
plt.axvline(0)
plt.xlabel('x')
plt.ylabel('y')
plt.title("2D Random Walk")
plt.show()