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);
}
}