% Topic: Generating desired continous random variable by using uniform random
% variable generator
% Case study: Making an exponetial distributed random variable
% If you have any question, send an email to: asahebpa@uwaterloo.ca
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

% See problems 1 and 2 from session 7 before looking through this code


Number_of_samples = 10000000; % Number of samples
lambda = 2;
Uniform = rand(1, Number_of_samples);

Expo = -log(1-Uniform)/lambda; % Invers of CDF as a function
% Now we have a matrix with elements which are exponetiatl random variables

%% Cheking PDF


[x, y] = hist(Expo,10000); % hist(r.v, Num): It devides axis into Num points and 
                            % Count number of elements in vector r.v which 
                            % lay between two different bins

plot(y,(x/Number_of_samples)/(y(3)-y(2)))