heads <- function(n,p) (1:n)[rbinom(n,1,p)==1] heads(10,3/4)