Return cartesian vectors uniformly picked on the unit ball in an
    arbitrary number of dimensions.

    The unit ball is the space enclosed by the unit sphere.

    The picking is done by rejection sampling in the unit cube.

    In 3-dimensional space, the fraction `\pi / 6 \sim 0.52` points are valid.

    Parameters
    ----------
    n: integer
        Number of points to return.
    d: integer
        Number of dimensions of the space in which the ball lives

    Returns
    -------
    r: array, shape (n, d)
        Sample cartesian vectors.

def ball_pick(n, d, rng=None):
    """Return cartesian vectors uniformly picked on the unit ball in an
    arbitrary number of dimensions.

    The unit ball is the space enclosed by the unit sphere.

    The picking is done by rejection sampling in the unit cube.

    In 3-dimensional space, the fraction `\pi / 6 \sim 0.52` points are valid.

    Parameters
    ----------
    n: integer
        Number of points to return.
    d: integer
        Number of dimensions of the space in which the ball lives

    Returns
    -------
    r: array, shape (n, d)
        Sample cartesian vectors.
    """
    def valid(r):
        return vector_mag_sq(r) < 1.0
    return rejection_pick(L=2.0, n=n, d=d, valid=valid, rng=rng)