package com.payease.utils;

import java.util.Random;

/**
 * liuxiaoming
 * 2017-11-20
 */
public class KeyUtil {

    /**
     * 随机数 位数自定
     * @return
     */
    public static String RandomNumber(Integer num){

        int a[] = new int[num];
        String ram ="";
        for(int i=0;i<a.length;i++ ) {
            a[i] = (int)(10*(Math.random()));
            System.out.print(a[i]);
            ram += a[i];
        }
        return ram;
    }
    /**
     * 生成唯一主键
     * 格式: 时间+随机数(6位随机数)
     *  synchronized 多线程关键字
     */
    public static synchronized String getUniqueKey(){
        Random random = new Random();
        Integer number = random.nextInt(900000) + 100000; //六位随机数(五个零) 若七位随机数(六个零)

        return  System.currentTimeMillis() + String.valueOf(number); //系统时间 + 随机数 
    }
}

 

相关文章:

  • 2021-12-18
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
  • 2021-12-10
猜你喜欢
  • 2021-10-23
  • 2022-12-23
  • 2022-01-29
  • 2021-12-16
  • 2021-09-28
  • 2022-12-23
相关资源
相似解决方案