Automatic username generation
This is pretty simple. Create your module, then create a form "MyRegForm" where the user can input her email and (if needed) password (twice with the '#type' => 'password_confirm'). Then, in the submit() method create your user like this:

\Drupal\user\Entity\User::create([
            'name' =&gt; 'hGzfT54re39OpLLLk',
            'pass' =&gt; 'hGzfT54re39OpLLLk',
            'mail' =&gt; $data-&gt;mail,
            'status' =&gt; 1,
            'init' =&gt; $data-&gt;mail,
            'created' =&gt; time(),
            'changed' =&gt; time(),
            'login' =&gt; 0,
            'access' =&gt; 0,
        ])-&gt;save();


The change the username and add whatever roles you need with code like

    $tuser = user_load_by_name('hGzfT54re39OpLLLk');
    $tuser-&gt;setUsername('My super name logic');
    $tuser-&gt;addRole("whatever");
    $tuser-&gt;save();
    $rc = $tuser-&gt;id();


If you don't want to create your own form for registration, go for hook_form_alter and set the #access to the "name" field to false and add a #default_value.