zoukankan      html  css  js  c++  java
  • 唯一值

      public static Long createID() {
    Random rand = new Random();
    StringBuffer sb = new StringBuffer();
    //等待1秒,指定根据时间毫秒数获取13位不重复数字
    // try {
    // Thread.sleep(1);
    // } catch (InterruptedException e) {
    // e.printStackTrace();
    // System.out.println("生成唯一数 createID exception()");
    // } finally {
    // sb.append(System.currentTimeMillis() + "");
    // }
    //固定5位随机数
    for (int i = 1; i <= 5; i++) {
    //随机生成1-9自然数
    int randNum = rand.nextInt(9) + 1;
    sb = sb.append(randNum + "");
    }
    return Long.parseLong(System.currentTimeMillis() + String.valueOf(sb));
    }

    public static void main(String[] args) {
    //压力测试生成唯一值毫秒数
    long startTime = System.currentTimeMillis();
    for (int i = 0; i < 3000; i++) {
    System.out.println(createID());
    }
    long endTime = System.currentTimeMillis();
    float excTime = (float) (endTime - startTime) / 1000;
    System.out.println("执行时间为:" + excTime + "s");
    }
  • 相关阅读:
    【随笔】新博客
    【Linux】grep命令
    【C/C++】C++11 Move, Forward
    【C/C++】C++11 Variadic Templates
    【C/C++】C++11 Lambda
    【Linux】gdb调试
    【C/C++】数组 & 指针
    【PAT】反转链表
    【OS】Process & Thread
    【Python】Scrapy基础
  • 原文地址:https://www.cnblogs.com/mangwusuozhi/p/14255562.html
Copyright © 2011-2022 走看看