design patterns: can valuables create their own value?

Suppose you have a username value object that has formatting rules, for example,

class Username
{
    private $username; 

    public function __construct(string $username)
    {
        // thrown an exception if invalid regex ^(a-zA-Z0-9)+$
        // ...

        $this->username = $username;
    }
}

As in the previous case, the plain string would generally pass from "outside" to validate the username.

My question is, can valuables have "additional functionality" such as generating their own value, such as generating a username? e.g.,

class Username
{
    private $username; 

    // original __constuct() remains here
    // ...

    public function generateUsername(UserRepository $userRepository): self
    {
        $username = $this->generateRandomUsername();

        if (!$userRepository->userExist($username))           
             return new self($username);
    }
}

The example is just a quick pseudocode of the idea, but the idea is generateUsername() it would take UserRepository to validate if the newly generated username from within the class does not yet exist in the database.

Can valuables have a functionality like this, or should they behave more like the first example, where they only accept and validate entry from the "outside"?