It's not clear how you want to generate the username but this is a way to get a unique one. Hope it gives you an idea where to start:
EDIT:
I edited the code so it generates unique usernames with a maximum of 6 characters. The for loop is just for demonstration purposes.
$basename = 'username';
$usernames = array();
for ($i = 0; $i < 25; $i++) {
$username = substr($basename,0,6);
$number = 0;
while(in_array($username, $usernames)) {
$length = strlen($username)-strlen($number);
$username = substr($basename,0,$length).$number;
$number++;
}
$usernames[] = $username;
echo $username.'<br>';
}