--- random_captcha_type/random_captcha_type.module.orig	2008-04-07 15:55:02.000000000 -0700
+++ random_captcha_type/random_captcha_type.module	2009-04-12 09:23:45.352434946 -0700
@@ -45,6 +45,7 @@ function random_captcha_type_captcha($op
       }
       return array('Random CAPTCHA type');
     case 'generate':
+      $captcha = array();
       if ($captcha_type == 'Random CAPTCHA type') {
         require_once('random_captcha_type.inc');
         if (isset($_POST['random_captcha_type'])) {
@@ -66,7 +67,26 @@ function random_captcha_type_captcha($op
           '#type' => 'hidden',
           '#value' => $module_and_type,
         );
-        return $captcha;
       }
+      return $captcha;
+    case 'preprocess':
+      $result = FALSE;
+      if ($captcha_type == 'Random CAPTCHA type') {
+        require_once('random_captcha_type.inc');
+        if (isset($_POST['random_captcha_type'])) {
+          // If this is a POST request, we're possibly in a validation phase
+          // so the CAPTCHA type should be the same as in the originating form
+          $module_and_type = $_POST['random_captcha_type'];
+        }
+        else {
+          // If not, just pick a random one
+          $types = _random_captcha_type_get_enabled_types();
+          $module_and_type = $types[array_rand($types)];
+        }
+        list($module, $type) = explode('/', $module_and_type);
+        // Call the preprocess CAPTCHA hook
+        $result = module_invoke($module, 'captcha', $op, $type);
+      }
+      return $result;
   }
 }
