Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can’t figure out how to set my random number between 1 and 100

Tags:

android

I just want to make a basic counter and for some reason I can't figure out how to draw a random number between 1 and 100. Can someone please explain what I have to do to draw a random number between 1 and 100?

This is what I came up with until now:

int value;
private int count = 1;

Random rand;


}
like image 905
baron dune Avatar asked Jan 10 '12 11:01

baron dune


People also ask

How do you generate a random number in range 1 100?

The function to use is sample() which shuffles the input list, in the example below it shuffles the created list range(1,101) . That is to say, range(1,101) creates a list of numbers 1 to 100. Then the function sample() shuffles that list in random order.

How do I get random numbers from 1 to 100 in Excel?

Select the cells in which you want to get the random numbers. In the active cell, enter =RAND() Hold the Control key and Press Enter. Select all the cell (where you have the result of the RAND function) and convert it to values.


1 Answers

  Random randomGenerator = new Random();

  int randomInt = randomGenerator.nextInt(100);
  log("Generated : " + randomInt);
like image 140
Kamal Avatar answered Sep 27 '22 18:09

Kamal