rand(3)
randn(1, 5)
randi(c(1,6), 1, 10)
U <- randp(1000, 2)
plot(U[, 1], U[, 2], pch="+")
#-- v is 2 independent normally distributed elements
# u <- randp(1); r <- t(u) %*% u
# v <- sqrt(-2 * log(r)/r) * u
n <- 5000; U <- randp(n)
R <- apply(U*U, 1, sum)
P <- sqrt(-2 * log(R)/R) * U # rnorm(2*n)
hist(c(P))
Run the code above in your browser using DataLab