# first define n (number of objects) and N (number of repetitions) # match = function(n) { # # define x as ordered integers 1:n x = (1:n) # # randomize values of x into y y = sample(x,n,replace=FALSE) # # check for matches, record in match match = (x==y) # # count number of matches nummatches = sum(match) } # replicate(N, match(n)) -> matchresults hist(matchresults) probs = table(matchresults)/N; probs probatleastone = 1 - probs[1]; probatleastone