Cache + random + hook_form_user_register_form_alter for a captcha purpose, I'm trying to set a random number in the hook_form_user_register_form_alter 

For example :

function my_module_form_user_register_form_alter(&amp;$form, &amp;$form_state) {
    $random_case = rand(0, 3);
    $form["random"] = array(
        "#type" =&gt; "textfield"
        , "#title" =&gt; ""
        , "#disabled" =&gt; 0
        , "#value" =&gt; $random_case
        , "#description" =&gt; null
        , "#weight" =&gt; -2
    );
}


When cache is disabled it's working as intended.

when I enable the cache the random number is always the same until I flush all caches.
I tried to flush cache programmatically, but it doesn't seem to work. What can I do ? 

if I put a 

die($random_case);


It's working but I think it's because drupal can't put the hook inside the cache.

Best regards.
When the forms cached, it caches the original, unprocessed $form array, and the builder functions are not called again. 

you can explicitly set cache off by setting $form_state['no_cache'] = TRUE;. Note that this has potential to break Ajax forms.