function r = ricernd(k_factor,k)
%RICERND Random samples from the Rice/Rician probability distribution.
%   r = ricernd(v, s) returns random sample(s) from the Rice (aka Rician) 
%   distribution with parameters v and s.
%   (either v or s may be arrays, if both are, they must match in size)
%
%   R ~ Rice(v, s) if R = sqrt(X^2 + Y^2), where X ~ N(v*cos(a), s^2)
%   andnn
%   Y ~ N(v*sin(a), s^2) are independent normal distributions (any real a).
%   Note that v and s are *nrot* the mean and standard deviation of R!
s = sqrt(1/(2*(k_factor+1)));
v = sqrt(k_factor/(k_factor+1))*ones(1,k);
x = s .* randn(1,k) + v;
y = s .* randn(1,k);
r = sqrt(x.^2 + y.^2);
