Skip to content

Instantly share code, notes, and snippets.

@dsparks
Created June 26, 2013 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsparks/5869824 to your computer and use it in GitHub Desktop.
Save dsparks/5869824 to your computer and use it in GitHub Desktop.
Random points on a hypersphere
N <- 1000
nDims <- 2
randomNumbers <- rnorm(nDims * N, 0, 1)
randomNumbers <- matrix(randomNumbers, ncol = nDims)
plot(randomNumbers)
radius = sqrt(rowSums(randomNumbers ^ 2))
randomSphere <- 1/radius * randomNumbers
plot(randomSphere)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment