generate_norm1 <- function(n, mu, sigma){
uni_matrix <- matrix(runif(30*n, -1, 1), n)
out <- apply(uni_matrix, 1, sum)
out <- out*sigma/sqrt(10) + mu
return(out)
}
generate_norm2 <- function(n, mu, sigma){
uni_matrix <- runif(30*n, -1, 1)
dim(uni_matrix) <- c(n,30)
out <- apply(out, 1, sum)
out <- out*sigma/sqrt(10) + mu
return(out)
}
generate_norm3 <- function(n, mu, sigma){
out <- runif(30*n, -1, 1)
dim(out) <- c(n,30)
out <- apply(out, 1, sum)*sigma/sqrt(10) + mu
return(out)
}
print(system.time(rn<-generate_norm1(n,1,2)))
print(system.time(rn<-generate_norm2(n,1,2)))
print(system.time(rn<-generate_norm3(n,1,2)))