I can't figure out how to set my random number from 1 to 100

I just want to create a basic counter, and for some reason I cannot figure out how to draw a random number from 1 to 100. Can someone explain what I need to do to draw a random number from 1 to 100

This is what I have come to so far:

int value; private int count = 1; Random rand; } 
+6
source share
8 answers
  Random randomGenerator = new Random(); int randomInt = randomGenerator.nextInt(100); log("Generated : " + randomInt); 
+16
source

It looks like for integers you need to create a random generator object:

 //at the start of your program Random generator = new Random(); //each time you need a random number int myrandomnumber = generator.nextInt()%100+1; 
+4
source
 mRandom = minLimit + (int) (Math.random() * ((maxlimit - minLimit) + 1)); 
+3
source

Try using this.

 Random rander = new Random(); int Max = 100; int Min = 1; rander.nextInt(Max - Min + 1) + Min ; 
+3
source

use this:

 int Min = 1; int Max = 100; int rndNum = Math.random() * ( Max - Min ); 
+2
source

look through this one , it has its answer.

0
source

It is not that difficult.

Try using this:

int randomNum = (int) Math.ceil(Math.random() * 100);

For a number from 0 to 100. Or, if you need a value between X and Y, use the following:

int randomNum = (int) Math.ceil(Math.random() * X) + Y;

Where Y is the smallest amount you want and X is the largest number you want to add to it (e.g. Y = 75 and X = 25 so that you get a number from 75 to 100 (75 + 25))

0
source

Since the question was answered by ben, I would like to say that you can also use float double http://developer.android.com/reference/java/util/Random.html

0
source

Source: https://habr.com/ru/post/905608/


All Articles