掃二維碼與項目經(jīng)理溝通
我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流
在 Java 中,我們可以使用以下類創(chuàng)建隨機數(shù):、、.讓我們看看它們中的每一個的快速示例,然后我們將討論它們的差異。RandomSecureRandomThreadLocalRandomSplittableRandom

十載的三穗網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。成都全網(wǎng)營銷的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整三穗建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。創(chuàng)新互聯(lián)建站從事“三穗網(wǎng)站設(shè)計”,“三穗網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。
package com.logicbig.example;
import java.util.SplittableRandom;
public class SplittableRandomExample {
public static void main(String[] args){
//creating a random int
System.out.println("-- single random int --");
int i = new SplittableRandom().nextInt(10, 100);
System.out.println(i);
//creating stream of ints
System.out.println("-- stream --");
new SplittableRandom()
.ints(5, 10, 100)
.forEach(System.out::println);
}
}
-- single random int --
49
-- stream --
73
35
50
44
88
package com.logicbig.example;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.concurrent.ThreadLocalRandom;
public class SecureRandomExample {
public static void main(String[] args) throws NoSuchAlgorithmException {
//creating a random int
System.out.println("-- single random int --");
int i = new SecureRandom().nextInt(100);
System.out.println(i);
//creating stream of ints
System.out.println("-- stream --");
new SecureRandom()
.ints(5, 10, 100)
.forEach(System.out::println);
}
}
-- single random int --
13
-- stream --
80
73
92
30
92
package com.logicbig.example;
import java.util.concurrent.ThreadLocalRandom;
public class ThreadLocalRandomExample {
public static void main(String[] args) {
//creating a random int
System.out.println("-- single random int --");
int i = ThreadLocalRandom.current().nextInt(10, 100);
System.out.println(i);
//creating stream of ints
System.out.println("-- stream --");
ThreadLocalRandom.current()
.ints(5, 10, 100)
.forEach(System.out::println);
}
}
-- single random int --
40
-- stream --
23
41
95
44
33
package com.logicbig.example;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
public class RandomExample {
public static void main(String[] args){
//creating a random int
System.out.println("-- single random int --");
int i = new Random().nextInt(100);
System.out.println(i);
//creating stream of ints
System.out.println("-- stream --");
new Random().ints(5, 10, 100)
.forEach(System.out::println);
}
}
-- single random int --
18
-- stream --
13
60
41
68
32
上述每個類都有各種方法(或多或少)來生成單獨的整數(shù)、浮點數(shù)、雙精度、長整型、布爾值、 上面的每個類都有各種方法來生成 IntStream、DoubleStream 和 LongStream。

我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流