など、UUIDを使用して乱数を生成します

パッケージテスト。

輸入java.util.Randomの。
輸入java.util.UUID;
輸入java.util.concurrent.ThreadLocalRandom;

{クラスRandomdemo公共
のpublic static無効メイン(文字列[] args)を{
/ **
*公共ランダム()(シードとしてデフォルトシード現在のシステム時刻
指定されたパブリックランダムシード*(ロングSEED)に応じ

/
ランダムランダムランダム新しい新しいです= (10);
のSystem.out.println(random.nextBoolean());
のSystem.out.println(random.nextDouble());
のSystem.out.println(にRandom.nextInt());
System.out.printlnは(ランダム.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);

}

}

おすすめ

転載: www.cnblogs.com/thttt/p/11825968.html