You are here

function _math_captcha_subtraction_challenge in CAPTCHA Pack 5

Same name and namespace in other branches
  1. 8 math_captcha/math_captcha.challenge.inc \_math_captcha_subtraction_challenge()
  2. 6 math_captcha/math_captcha.challenge.inc \_math_captcha_subtraction_challenge()
  3. 7 math_captcha/math_captcha.challenge.inc \_math_captcha_subtraction_challenge()

function for subtraction challenges

File

math_captcha/math_captcha.module, line 240

Code

function _math_captcha_subtraction_challenge() {
  $argmax = intval(variable_get('math_captcha_subtraction_argmax', 10));
  if (variable_get('math_captcha_subtraction_allow_negative', FALSE)) {
    $x = mt_rand(-$argmax, $argmax);
    $y = mt_rand(-$argmax, $argmax);
  }
  else {
    $y = mt_rand(0, $argmax);
    $x = mt_rand($y, $argmax);
  }
  $solution = $x - $y;
  $maxlength = strlen(strval($argmax + $argmax)) + intval(variable_get('math_captcha_subtraction_allow_negative', FALSE));
  return _math_captcha_build_captcha($x, $y, '-', $solution, $maxlength);
}