The Random Walker Printer Draw a program or function that will write to STDOUT n times (each for one step) a string that contains a dot . at the location of the walker. The program also needs to write a line every s seconds (or wait s seconds after each line).

A random walk is a mathematical formalization of a path that consists of a succession of random steps (wiki), such that every new step will be the last step plus a new value, so any tstep value is just the sum of all the random values before ir plus the initial value.

The program should take 2 inputs and will use only spaces " " and dots "." on the output. The start value of the walker will be 20 such that the output should be a dot after 19 spaces.

                  . #19 spaces then a dot


Every new step the value will be the last value of the walker plus one of these[-2-1,0,1,2](20% chance each). After the new position is printed the program should wait s seconds and the go to the next step. If the step takes the walker outsite the range 1 to 40 it should be just ignored and the walker position stays the same. The number of spaces will always be a number from 0 to 39.

Example

#input
Mywalk(s = 0.1, n = 30)

#output
                     .
                    .
                      .
                        .
                          .
                           .
                            .
                          .
                         .
                          .
                           .
                            .
                           .
                          .
                           .
                           .
                         .
                         .
                          .
                            .
                           .
                          .
                           .
                           .
                           .
                         .
                          .
                         .
                          .
                          .


Considerations


You may take the input as any reasonable format
The shortest code wins
It's okay if your program only accept the seconds as integers
Matlab, 112
The core idea is generating a list of possible next positions and then uniformly drawing one of them. If we are e.g. at position $l=1$ the possible steps would be [-1,0,1,2,3] Of course if we would chose -1 that would be invalid and we would have to stay at the same position. Thats why we replace the invalid positions with the current position, [1,0,1,2,3], and then randomly chose an element from this updated list.
The OP asked us tho draw the program, so here we go:

The transcription:
function c(n,s);
l=19;                             %initialize position
for k=1:n;                          
    disp([ones(1,l)*32,'.']);     %print the line
    z=(-2:2)+l;                   %get vector of possible next steps (for l=1 we get [-1,0,1,2,3])
    z(z&lt;0)=l;                     %prune invalids: here we just replace the the invalid positions with the current position
    z(z&gt;39)=l;                    %   this ensures the same behaivour as staying in the same spot when going outside of the range
    l=z(randi(5));                %draw random sample of those
    pause(s);
end