#Bash, 81
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 . . . . . $