You can compute the number of ones, n
; bulid a vector with n
ones and N-n
zeros (in that order); and then randomly permute that vector:
p = .5;
N = 8;
n = round(N*p); %// desired number of ones
result = [ ones(1,n) zeros(1,N-n) ]; %// n ones and N-n zeros
result = result(randperm(N)); %// random order