2010-04-30

Principle of Random Permutation

You may use 'sample' function in R, and it is sufficient usually.
The following is one of my favoriate code. Here it is expressed in R language.

# R coding showing the principle of random permutation
RanPermute <- function(n)
{
    x <- cbind(1:n, runif(n))
    return(x[order(x[,2]),1])
}

# Test code
RanPermute(100)

No comments:

Post a Comment