慕犹清

关注

jave中的Random中rand.nextInt(int n )的取值范围

慕犹清

关注

阅读 35

2023-03-28


1.要求在10到300中产生随机数[10,300]包含10和300.

int randNum = rand.nextInt(300-10+1) + 10;

rand.nextInt(300-10+1)=rand.nextInt(291)意思是产生[0,291)不包括291再加10就是[10,301)不包括301,如果要包括300所以要 rand.nextInt(300-10+1)里面要加1.

如果是[10,300)不包括300就是 rand.nextInt(300-10)+10,不要加1.


相关推荐

登高且赋

java中的int取值的范围

登高且赋 47 0 0

佛贝鲁先生

java.util.Random 类的 nextInt(int num )

佛贝鲁先生 179 0 0

无愠色

python int取值范围

无愠色 90 0 0

q松_松q

C++整型int的取值范围

q松_松q 76 0 0

Brose

Int31n() ---- math/rand/rand.go

Brose 36 0 0

月孛星君

计算n的阶乘,n的取值范围1到2000(代码实现)

月孛星君 121 0 0

Soy丶sauce

numpy中的np.random.rand、np.random.randn、np.random.randint、np.random.uniform等用法

Soy丶sauce 81 0 0

上善若水山西太原

为什么int8的取值范围是-128 - 127

上善若水山西太原 74 0 0

知年_7740

JAVA与c#中byte取值范围的差异

知年_7740 60 0 0

读思意行

mysql的数据类型int、bigint、smallint 和 tinyint取值范围

读思意行 34 0 0

精彩评论(0)

0 0 举报