0
int number_of_rounds = (int)(Math.abs(Math.log10(ma-mi+1)/Math.log10(2)));

how can i generate positive integer value, I am new here so if i do any mistake please guide me

seenukarthi
  • 8,241
  • 10
  • 47
  • 68
  • In which way does the code you show not work? Pleas provide a [mre] which demonstrates that. – Yunnosch Mar 08 '22 at 07:08
  • 1
    Does this answer your question? [How do I generate random integers within a specific range in Java?](https://stackoverflow.com/questions/363681/how-do-i-generate-random-integers-within-a-specific-range-in-java) – seenukarthi Mar 08 '22 at 07:10

1 Answers1

1

To generate positive integer numbers you simply need the Random class and invoke the nextInt(int bound) method. This method will return an integer value between 0 and bound-1. If you need a value between a and b, then you can simply add a as an offset of the nextInt result and use (b - a) as the upper bound.

For example:

Random rand = new Random();
int x = rand.nextInt(10);       //returns an integer between 0 and 9
int y = rand.nextInt(10) + 10;  //returns an integer between 10 and 19