JAVA 时间戳+随机数生成唯一ID

/**

  • @Title: IDUtils.java
  • @Package com.createid
  • @Description: TODO(用一句话描述该文件做什么)
  • @author Aaron·Li
  • @date 2017年9月20日 上午11:51:31
  • @version V1.0
    */
    package com.yitianyike.utils;

/**

  • @author Aaron·Li

  • @date 2017年9月20日 上午11:51:31
    */
    public class IDUtils {
    private static byte[] lock = new byte[0];

    // 位数,默认是8位
    private final static long w = 100000000;

    public static String createID() {
    long r = 0;
    synchronized (lock) {
    r = (long) ((Math.random() + 1) * w);
    }

     return System.currentTimeMillis() + String.valueOf(r).substring(1);
    

    }
    }

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容