开发者

How do I randomly generate a number between 75 - 100%?

开发者 https://www.devze.com 2023-01-26 19:32 出处:网络
I know how to do it between 0 and 100, but I can I set the floor? This is how I do 0 - 100.. int randomNum = (int) Math.ceil(Math.random(开发者_开发知识库) * 100);

I know how to do it between 0 and 100, but I can I set the floor?

This is how I do 0 - 100..

int randomNum = (int) Math.ceil(Math.random(开发者_开发知识库) * 100);


Generate a random number from 0 to 25 and add 75. :)


int randomNum = (int) Math.ceil(Math.random() * 25) + 75;


Generate a number between 0 and 25 and then add 75.


Do it between zero and 25 and add 75.


I know this is answered already but correct answer did not have code snippet. So here is a little code snippet:

int randomNum = 0;
Random ran = new Random();
randomNum  = ran.nextInt(25) + 75;
0

精彩评论

暂无评论...
验证码 换一张
取 消