Carlettos

23.a)

Oct 23rd, 2020
1,839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.29 KB | None | 0 0
  1. import random as rnd
  2. import matplotlib.pyplot as plt
  3.  
  4.  
  5. def moverse(x):
  6.     if rnd.random() <= p:
  7.         x += rnd.random()
  8.     else:
  9.         x -= rnd.random()
  10.     return x
  11.  
  12.  
  13. n = 1000
  14. p = 0.6
  15. x = [0]
  16.  
  17. for i in range(n):
  18.     x.append(moverse(x[i]))
  19.  
  20. plt.plot(x)
  21. plt.show()
  22.  
Advertisement
Add Comment
Please, Sign In to add comment