Bathri Nathan Bathri Nathan - 1 year ago 69
Java Question

How can I get a random number between two ranges?

I need to show the numbers 1-10 in a random order. An example outpue while executing first time would be:

. An example while executing second time would be:

Will the following code print all date between ranges in random?

Random r = new Random();
int i1 = r.nextInt(80 - 65) + 65;

Answer Source

You can use the Collections.shuffle() method. (more info on this SO question)

In your example:

List<int> numbers = new ArrayList<int>();
int min = 65;
int max = 85;
for (int i = min; i <= max; i++) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download