package com.ruoyi.web.modules.account.util;

import java.security.SecureRandom;

public class UserNameGenerator {

    // 字符池：大小写字母 + 数字（去掉易混淆的 0/O/I/l）
    private static final String CHAR_POOL = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz123456789";
    private static final int LENGTH = 8;
    private static final SecureRandom RANDOM = new SecureRandom();

    /**
     * 生成 8 位唯一随机用户名（如 fUZGEs0Z）
     */
    public static String generateUniqueName() {
        StringBuilder sb = new StringBuilder(LENGTH);
        for (int i = 0; i < LENGTH; i++) {
            int index = RANDOM.nextInt(CHAR_POOL.length());
            sb.append(CHAR_POOL.charAt(index));
        }
        return sb.toString();
    }
}