package com.fs.utils;


import java.util.Random;

public class DomainUtil {

    private static final String LETTER = "abcdefghijklmnopqrstuvwxyz";
    private static final Random RANDOM = new Random();

    /**
     * 生成二级域名
     * @param domain 主域名
     * @param length 名称长度
     * @param suffix 后缀
     * @return  二级域名
     */
    public static String generateSubDomain(String domain, int length, String suffix) {
        if (length < 6) {
            length = 6;
        }
        StringBuilder sub = new StringBuilder(length);
        for (int i = 0; i < length; i++) {
            sub.append(LETTER.charAt(RANDOM.nextInt(LETTER.length())));
        }
        return sub + "-" + suffix + "." + domain;
    }
}
