This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/statistics/exercises/randomwalk.m

9 lines
188 B
Matlab

function x = randomwalk(n,p)
% returns a random wolk with n steps and
% probability p for positive steps.
r = rand(n,1);
r(r<p) = -1.0;
r(r>=p) = +1.0;
x = cumsum(r);
end