package com.fdkankan.ucenter.common;

import java.security.SecureRandom;
import java.text.SimpleDateFormat;
import java.util.Date;

public class RandomCodeUtil {

    private static final String CHARACTERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    private static final SecureRandom random = new SecureRandom();
    public static synchronized String generateCode(String pre,Integer count) {
        StringBuilder code = new StringBuilder(pre);
        for (int i = 0; i < count; i++) {
            int index = random.nextInt(CHARACTERS.length());
            code.append(CHARACTERS.charAt(index));
        }

        return code.toString();
    }

    public static void main(String[] args) {
        String format1 = new SimpleDateFormat("yyMMdd").format(new Date());
        System.out.println(format1);
        System.out.println(generateCode("W-",8));
    }
}
