'use strict';

// MODULES //

var pow = require( '@stdlib/math/base/special/pow' );
var ln = require( '@stdlib/math/base/special/ln' );


// MAIN //

/**
* Handles case where both `alpha` and `beta` are greater than `1.0`.
*
* @private
* @param {Function} rand - PRNG for uniformly distributed numbers
* @param {Function} rnorm - PRNG for normally distributed numbers
* @param {PositiveNumber} alpha - first shape parameter
* @param {PositiveNumber} beta - second shape parameter
* @returns {Probability} pseudorandom number
*/
function sample( rand, rnorm, alpha, beta ) {
	var sigma;
	var flg;
	var mu;
	var A;
	var B;
	var C;
	var L;
	var s;
	var u;
	var x;
	var y;

	A = alpha - 1.0;
	B = beta - 1.0;
	C = A + B;
	L = C * ln( C );
	mu = A / C;
	sigma = 0.5 / pow( C, 0.5 );

	flg = true;
	while ( flg === true ) {
		s = rnorm( 0.0, 1.0 );
		x = mu + s*sigma;
		if ( x >= 0.0 && x <= 1.0 ) {
			u = rand();
			y = A * ln(x/A) + B * ln((1.0-x)/B) + L + 0.5*s*s;
			if ( y >= ln( u ) ) {
				flg = false;
			}
		}
	}
	return x;
} // end FUNCTION sample()


// EXPORTS //

module.exports = sample;

@@ -851,15 +851,17 @@
 u + 
+(
 s*sigma
+)
 ;%0A%09%09
@@ -923,14 +923,23 @@
  ln(
+ 
 x/A
-)
+ );%0A%09%09%09y
  +
+=
  B *
@@ -953,25 +953,36 @@
 0-x)
-/B)
+ / B);%0A%09%09%09y
  +
+=
  L + 
+(
 0.5*s*s
+)
 ;%0A%09%09

Fix lint errors