码迷,mamicode.com
首页 > 其他好文 > 详细

使用uuid生成随机数、等等

时间:2019-11-09 15:21:32      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:class   时间   sys   ++   dom1   cas   生成随机数   adl   local   

package test;

import java.util.Random;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

public class Randomdemo {
public static void main(String[] args) {
/**
* public Random()( 使用默认的种子 一当前系统时间作为种子
* public Random(long seed)根据指定种子

/
Random random = new Random(10);
System.out.println(random.nextBoolean());
System.out.println(random.nextDouble());
System.out.println(random.nextInt());
System.out.println(random.nextInt(100));
System.out.println("---------");

    //ThreadLocalRandom 是Random类的子类 ,在多线程的情况下,可以减少多
    ThreadLocalRandom random1 = ThreadLocalRandom.current();
    System.out.println(random1.nextInt(50,100));

    /**
    * UUID 通用唯一识别 : 在一台机器上生成的数字,保证唯一
     * 类似生成Mac地址
    * */

    String string  = UUID.randomUUID().toString();
    System.out.println(string);

    //生成一个5位数的随机数 验证码 里面包含大写小写 数字的数

    String string1 = "ABCDEFFF";
    string1 += string.toLowerCase();
    string1 += "0123456789";
    StringBuilder stringBuilder = new StringBuilder(5);
    for (int i = 0 ;i<5;i++){
        char ch = string1.charAt(new Random().nextInt(string1.length()));
        stringBuilder.append(ch);
    }
    System.out.println(stringBuilder);

}

}

使用uuid生成随机数、等等

标签:class   时间   sys   ++   dom1   cas   生成随机数   adl   local   

原文地址:https://www.cnblogs.com/thttt/p/11825968.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!