Advertisement
Guest User

Python 1D Random Walk iterations test

a guest
Jan 5th, 2014
133
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. import sys
  3. import random
  4.  
  5. range = int(sys.argv[1])
  6. v = 0
  7. vmin = 0
  8. vmax = 0
  9. i = 0
  10. while vmax - vmin < range:
  11.     v += random.randint(0, 1) * 2 - 1
  12.     if v < vmin:
  13.         vmin = v
  14.     if v > vmax:
  15.         vmax = v
  16.     i += 1
  17. print i
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement