n = 100000;

% Naive way
% 1
x = rand(n,1) * 2 - 1;
y = rand(n,1) * 2 - 1;
% 2
antecedent = x.^2 + y.^2 < 1;
% 3
consequent = x > .5;
prob1 = sum(antecedent & consequent) / sum(antecedent);

% Less naive way
theta = rand(n,1) * 2 * pi;
r = sqrt(rand(n,1));
x = r .* cos(theta);
y = r .* sin(theta);
prob2 = sum(x > .5) / n;
