zoukankan      html  css  js  c++  java
  • 使用uuid生成随机数、等等

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

    }

  • 相关阅读:
    链表的逆置(无聊而写)
    C
    大型分布式站点的技术需求
    leetcode第一刷_Best Time to Buy and Sell Stock
    微商行业面临洗礼,微盟萌店是否能完毕“神补刀”?
    oracle函数 CONCAT(c1,c2)
    oracle函数 CHR(n1)
    oracle函数 ASCII(x1)
    oracle函数 INTERVAL c1 set1
    oracle函数 SESSIONTIMEZONE
  • 原文地址:https://www.cnblogs.com/thttt/p/11825968.html
Copyright © 2011-2022 走看看