Ask a simple question, spend the next forty minutes sifting through integral tables. Earlier, I took some code that was uniformly selecting points from a square centered at the origin and converted it to code using points from a normal distribution. For my purposes, I used a standard-deviation for the normal distribution that was half of the in-radius of the box. It wasn’t at all exact in any way.

What if I wanted to be exact? Suppose I wanted to switch from points uniformly distributed in a box to points from a normal distribution while maintaining the *expected distance from the selected point to the origin*.

What exactly is the expected distance from a selected point to the origin if one picks each coordinate for the point from a uniform distribution on the range [-1,+1]? Let’s start with the one-dimensional case. The probability density is everywhere. So, the answer is as we would expect.

How about two dimensions? This is immediately more awkward. The one-dimensional disk looks exactly like the one-dimensional square. In two dimensions, the disk and square are quite different. We either have to integrate over the square and calculate the radius of each point, or we have to integrate over increasing radii and be careful once we get to the in-radius of the square. (image created in Lisp using Zach's Vecto library)

I originally chose to try to integrate over the square. The probability density is everywhere. This means the expected radius is . This gets to be no fun very fast since the inner integral comes out with a logarithm in it. I mean, do you want to finish this integral?

It may be easy. I didn’t want to mess with it. I suppose once you evaluate the terms, it reduces a fair bit (if I did that all right):

I still don’t want to touch it.

So, how about integrating over the radii? Again, the probability density is everywhere. This makes the expected radius:

With a little massaging, you can move the from the second integral into the first instead:

This is hardly consolation though. Here is where we get lost in our table of integrals for the better part of an hour.

And, this is only the two-dimensional case! In my original problem, the ambient space was 32-dimensional. My, oh my.