def randsphere(n, rstate=None):
    """Draw a point uniformly within an `n`-dimensional unit sphere."""

    if rstate is None:
        rstate = np.random

    z = rstate.randn(n)  # initial n-dim vector
    zhat = z / lalg.norm(z)  # normalize
    xhat = zhat * rstate.rand()**(1./n)  # scale

    return xhat
Draw a point uniformly within an `n`-dimensional unit sphere.