/**
 * All rights Reserved, Designed By www.freemud.cn
 *
 * @Title: ValidationCode
 * @Package cn.freemud.util
 * @Description: 生成一串随机数字或者字母
 * @author: ping.wu
 * @date: 2018/4/16 18:14
 * @version V1.0
 * @Copyright: 2018 www.freemud.cn Inc. All rights reserved.
 * 注意：本内容仅限于上海非码科技内部传阅，禁止外泄以及用于其他的商业目
 */
package cn.freemud.utils;

import cn.freemud.id.sharding.DefaultKeyGenerator;

import java.util.Random;

public class ValidationCode {

    public static String getRandomString(int length) {
        String codeSerial = "1234567890abcdefghkmnpqrstwxyABCDEFGHKLMNPQRSTWXY";
        Random random = new Random();
        int n = codeSerial.length();
        StringBuffer code = new StringBuffer();

        for(int i = 0; i < length; ++i) {
            code.append(codeSerial.charAt(random.nextInt(n)));
        }

        return code.toString();
    }

    public static String getRandomNumber(int length) {
        String serial = "0123456789";
        Random random = new Random();
        int n = serial.length();
        StringBuffer code = new StringBuffer();

        for(int i = 0; i < length; ++i) {
            code.append(serial.charAt(random.nextInt(n)));
        }

        return code.toString();
    }

    public static String getRandomUuid() {
        DefaultKeyGenerator.setWorkerId(new Random().nextInt(100));
        DefaultKeyGenerator keyGenerator = new DefaultKeyGenerator();
        Long id = null;
        for (int i = 0; i < 100; i++) {
            id = (Long) keyGenerator.generateKey();
        }
        return getRandomNumber(3) + "" + id;
    }

    public static void main(String[] args) {
        System.out.println(getRandomUuid());
    }

}
