fork download
  1. from random import choice
  2. from matplotlib import pyplot
  3.  
  4. class random_walk_sim(object):
  5. def __init__(self, x, y):
  6. self.x = int(x)
  7. self.y = int(y)
  8. self.X = [x]
  9. self.Y = [y]
  10. def random_move(self):
  11. self.x += choice([-1, 0, 1])
  12. self.y += choice([-1, 0, 1])
  13. self.X += [self.x]
  14. self.Y += [self.y]
  15. def show_history(self):
  16. pyplot.plot(self.X, self.Y)
  17. pyplot.show()
  18.  
  19. if __name__ == '__main__':
  20. a = random_walk_sim(1, 1)
  21. [a.random_move() for i in range(1000)]
  22. a.show_history()
Success #stdin #stdout 0.73s 51892KB
stdin
Standard input is empty
stdout
Standard output is empty