%COINFLIPS: MATLAB script M-files with examples for 
%simulating a random variable that is 0 with probability .5
%and 1 with probability .5
%
%Conditional
if rand < .5
    X=0
else
    X=1
end
%Notice that the probability that rand is equal to 
%.5 is 1/(1 + 2^52). 
%Round
X = round(rand)
%Ceil
X = ceil(2*rand-1)
%Floor
X = floor(2*rand)
%Randi
X = randi(2)-1