Skip to main content
4 of 4
Commonmark migration

Bash, 81

for((s=20;i++<$1;t=s,s+=RANDOM%5-2,s=s<0|s>39?t:s)){ printf %${s}s.\\n sleep $2 } 

Edit: If the step takes the walker outsite the range 1 to 40 it should be just ignored and the walker position stays the same handled correctly.

Input from command-line options. E.g.:

$ ./randwalk.sh 5 0.5 . . . . . $ 
Digital Trauma
  • 73.8k
  • 10
  • 117
  • 268