#!/bin/bash

generateRandomUsername() 
{
    local random_username=""
    local length=${CFG_GENERATED_USER_LENGTH:-12}  # Default to 12 if not set
    
    while true; do
        # Generate username with letters only (lowercase)
        random_username=$(dd if=/dev/urandom bs=32 count=1 2>/dev/null | base64 | tr -d '+/=' | tr -cd '[:alpha:]' | head -c $length | tr '[:upper:]' '[:lower:]')
        if [[ "$random_username" =~ ^[a-zA-Z]+$ ]] && [ ${#random_username} -eq $length ]; then
            echo "$random_username"
            return 0
        fi
    done
}