public Instance sample(Random random){
  double[] center=getCenter();
  final int dimensions=center.length;
  final double sin[]=new double[dimensions - 1];
  final double cos[]=new double[dimensions - 1];
  final double length=random.nextDouble() * getRadius();
  double lastValue=1.0;
  for (int i=0; i < dimensions - 1; i++) {
    double angle=random.nextDouble() * 2 * Math.PI;
    sin[i]=lastValue * Math.sin(angle);
    cos[i]=Math.cos(angle);
    lastValue=sin[i];
  }
  double res[]=new double[dimensions];
  res[0]=center[0] + length * cos[0];
  for (int i=1; i < dimensions - 1; i++) {
    res[i]=center[i] + length * sin[i - 1] * cos[i];
  }
  res[dimensions - 1]=center[dimensions - 1] + length * sin[dimensions - 2];
  return new DenseInstance(1.0,res);
}

public Instance sample ( Random random ) { double [ ] center = getCenter ( ) ; final int dimensions = center . length ; final double sin [ ] = new double [ dimensions - 1 ] ; final double cos [ ] = new double [ dimensions - 1 ] ; final double length = random . nextDouble ( ) * getRadius ( ) ; double lastValue = 1.0 ; for ( int i = 0 ; i < dimensions - 1 ; i ++ ) { double angle = random . nextDouble ( ) * 2 * Math . PI ; sin [ i ] = lastValue * Math . sin ( angle ) ; cos [ i ] = Math . cos ( angle ) ; lastValue = sin [ i ] ; } double res [ ] = new double [ dimensions ] ; res [ 0 ] = center [ 0 ] + length * cos [ 0 ] ; for ( int i = 1 ; i < dimensions - 1 ; i ++ ) { res [ i ] = center [ i ] + length * sin [ i - 1 ] * cos [ i ] ; } res [ dimensions - 1 ] = center [ dimensions - 1 ] + length * sin [ dimensions - 2 ] ; return new DenseInstance ( 1.0 , res ) ; }
samples this cluster by returning a point from inside it .
