public double nextGaussian(){
  if (mHaveNextNextGaussian) {
    mHaveNextNextGaussian=false;
    return mNextNextGaussian;
  }
 else {
    double v1, v2, s;
    do {
      v1=2 * nextDouble() - 1;
      v2=2 * nextDouble() - 1;
      s=v1 * v1 + v2 * v2;
    }
 while (s >= 1 || s == 0);
    final double multiplier=StrictMath.sqrt(-2 * StrictMath.log(s) / s);
    mNextNextGaussian=v2 * multiplier;
    mHaveNextNextGaussian=true;
    return v1 * multiplier;
  }
}

public double nextGaussian ( ) { if ( mHaveNextNextGaussian ) { mHaveNextNextGaussian = false ; return mNextNextGaussian ; } else { double v1 , v2 , s ; do { v1 = 2 * nextDouble ( ) - 1 ; v2 = 2 * nextDouble ( ) - 1 ; s = v1 * v1 + v2 * v2 ; } while ( s >= 1 || s == 0 ) ; final double multiplier = StrictMath . sqrt ( - 2 * StrictMath . log ( s ) / s ) ; mNextNextGaussian = v2 * multiplier ; mHaveNextNextGaussian = true ; return v1 * multiplier ; } }
return the next gaussian see knuth , acp , section 3 . 4 . 1 algorithm c .
