function [x] = geometricGenerator(p)
%  Generate random variable x that follows geometric distribution with
%  parameter p.
sum = 0;  % summation 
U = rand;  % a (0,1) uniform distr. value
k = 0;
while U > sum,  % must be true when k=0.
    k = k+1;
    sum = sum + power((1-p), k-1)*p;
end
x = k;