def rejection_pick(L, n, d, valid, rng=None):
    """Return cartesian vectors uniformly picked in a space with an arbitrary
    number of dimensions, which is fully enclosed by a cube of finite length,
    using a supplied function which should evaluate whether a picked point lies
    within this space.

    The picking is done by rejection sampling in the cube.

    Parameters
    ----------
    L: float
        Side length of the enclosing cube.
    n: integer
        Number of points to return
    d: integer
        The number of dimensions of the space

    Returns
    -------
    r: array, shape (n, d)
        Sample cartesian vectors
    """
    if rng is None:
        rng = np.random
    rs = []
    while len(rs) < n:
        r = rng.uniform(-L / 2.0, L / 2.0, size=d)
        if valid(r):
            rs.append(r)
    return np.array(rs)
Return cartesian vectors uniformly picked in a space with an arbitrary
    number of dimensions, which is fully enclosed by a cube of finite length,
    using a supplied function which should evaluate whether a picked point lies
    within this space.

    The picking is done by rejection sampling in the cube.

    Parameters
    ----------
    L: float
        Side length of the enclosing cube.
    n: integer
        Number of points to return
    d: integer
        The number of dimensions of the space

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