class UnitSphereRandomVectorGenerator implements RandomVectorGenerator {

    public double[] nextVector() {
        final double[] v = new double[dimension];

        // See http://mathworld.wolfram.com/SpherePointPicking.html for example.
        // Pick a point by choosing a standard Gaussian for each element, and then
        // normalizing to unit length.
        double normSq = 0;
        for (int i = 0; i < dimension; i++) {
            final double comp = rand.nextGaussian();
            v[i] = comp;
            normSq += comp * comp;
        }

        final double f = 1 / FastMath.sqrt(normSq);
        for (int i = 0; i < dimension; i++) {
            v[i] *= f;
        }

        return v;
    }

    public  UnitSphereRandomVectorGenerator(final int dimension,
                                           final RandomGenerator rand);
    public  UnitSphereRandomVectorGenerator(final int dimension);

}