Replace username with unique hash when users delete their own accounts When users delete their own accounts (with the core function), I don't want the username to be replaced by anonymous, but with a hash string, for example anonymous-dhjf4ued.

I tried doing it with the Rules module, and I looked for modules that could do it, but I couldn't figure it out.

The reason this would be useful is because I have sites with a forum and threads are much more readable if you can still identify which users are the same (who responds to who) if there are two cancelled user accounts in a single thread.
You can use hook_user_cancel() like below:

  /**
   * Implements hook_user_cancel()
   */
    function example_user_cancel($edit, $account, $method) {
      // Define in which method you are canceling the account, else remove it and 
      // proceed with below code by removing this if condition.
      if ($method == 'user_cancel_block') {
        $user_load = user_load($account-&gt;uid);
        $user_load-&gt;name = 'anonymous-'.time();// Here you can add your random number.
        user_save($user_load);
      }
    }