U <- polar(1000, 2)
plot(U[, 1], U[, 2], pch="+")
#-- v is 2 independent normally distributed elements
# u <- polar(1); r <- t(u) %*% u
# v <- sqrt(-2 * log(r)/r) * u
n <- 5000; U <- polar(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