gendat <- function(iter, ncols, nrows) { set.seed(iter * nrows * ncols) # all configurations BUT the outcome have to be unique dat <- unique( matrix(sample(0:1, (ncols - 1)*nrows, replace = TRUE), ncol = ncols - 1) ) # now that configurations are unique, we can add the outcome dat <- cbind(dat, sample(0:1, nrow(dat), replace = TRUE)) if (ncols > length(LETTERS) + 1) { colnames(dat) <- c( paste("I", seq(ncols - 1), sep = ""), "OUT" ) } else { colnames(dat) <- c(LETTERS[seq(ncols - 1)], "OUT") } return(dat[order(dat[, ncols], decreasing = TRUE), ]) }