public double[] randSphere(int dimension) {
    int D = dimension;
    double[] x = new double[dimension];

    double length = 0;
    for (int i = 0; i < dimension; i++) {
      x[i] = 0.0;
    }

    // --------- Step 1. Direction

    for (int i = 0; i < D; i++) {
      x[i] = this.randNormal(0, 1);
      length += length + x[i] * x[i];
    }

    length = Math.sqrt(length);

    // --------- Step 2. Random radius

    double r = randomGenerator.nextDouble(0, 1);

    for (int i = 0; i < D; i++) {
      x[i] = r * x[i] / length;
    }

    return x;
  }
public double [ ] randSphere ( int dimension ) { int D = dimension ; double [ ] x = new double [ dimension ] ; double length = 0 ; for ( int i = 0 ; i < dimension ; i ++ ) { x [ i ] = 0.0 ; } for ( int i = 0 ; i < D ; i ++ ) { x [ i ] = this . randNormal ( 0 , 1 ) ; length += length + x [ i ] * x [ i ] ; } length = Math . sqrt ( length ) ; double r = randomGenerator . nextDouble ( 0 , 1 ) ; for ( int i = 0 ; i < D ; i ++ ) { x [ i ] = r * x [ i ] / length ; } return x ; }
Get a random point from an hypersphere (center = 0, radius = 1)
Code taken from Maurice Clerc's implementation

@param dimension
@return A pseudo random point