(* Simulation << Knox7/Util *) StepSize[p_] := If[RandomReal[] <= p, 1, -1] SimulatedRandomWalk[p_, n_, M0_] := Module[{statelist, done, currstate, nextstate}, statelist = {n}; currstate = n; done = (currstate <= 0) || (currstate >= M0); While[Not[done], nextstate = currstate + StepSize[p]; AppendTo[statelist, nextstate]; currstate = nextstate; done = (currstate <= 0) || (currstate >= M0)]; statelist] thewalk = SimulatedRandomWalk[0.5, 4, 8] ListPlot[thewalk, PlotStyle -> {PointSize[.015], Blue}] ListLinePlot[thewalk, PlotStyle -> {PointSize[.015], Blue}]