public double nextDouble(double k){
  double u, v, w, c, z;
  if (k <= 0.0)   throw new IllegalArgumentException();
  if (k_set != k) {
    tau=1.0 + Math.sqrt(1.0 + 4.0 * k * k);
    rho=(tau - Math.sqrt(2.0 * tau)) / (2.0 * k);
    r=(1.0 + rho * rho) / (2.0 * rho);
    k_set=k;
  }
  do {
    u=randomGenerator.raw();
    v=randomGenerator.raw();
    z=Math.cos(Math.PI * u);
    w=(1.0 + r * z) / (r + z);
    c=k * (r - w);
  }
 while ((c * (2.0 - c) < v) && (Math.log(c / v) + 1.0 < c));
  return (randomGenerator.raw() > 0.5) ? Math.acos(w) : -Math.acos(w);
}

public double nextDouble ( double k ) { double u , v , w , c , z ; if ( k <= 0.0 ) throw new IllegalArgumentException ( ) ; if ( k_set != k ) { tau = 1.0 + Math . sqrt ( 1.0 + 4.0 * k * k ) ; rho = ( tau - Math . sqrt ( 2.0 * tau ) ) / ( 2.0 * k ) ; r = ( 1.0 + rho * rho ) / ( 2.0 * rho ) ; k_set = k ; } do { u = randomGenerator . raw ( ) ; v = randomGenerator . raw ( ) ; z = Math . cos ( Math . PI * u ) ; w = ( 1.0 + r * z ) / ( r + z ) ; c = k * ( r - w ) ; } while ( ( c * ( 2.0 - c ) < v ) && ( Math . log ( c / v ) + 1.0 < c ) ) ; return ( randomGenerator . raw ( ) > 0.5 ) ? Math . acos ( w ) : - Math . acos ( w ) ; }
returns a random number from the distribution ; bypasses the internal state .
