Random walk function now much more general