1
I am developing an application in Java and in my controller I have a function that generates random numbers. Example:
In my first column I want you to manage from 0 to 8, so far OK.
In the second column I want you to manage 9 to 17, then in this case I can’t do it because I can’t determine which number x
will start, because by default it counts with the beginning at 0.
I mean, I want you to run 0-9, then 9-17, then 18-25 and so on...
Follow my code below:
public void grupoDeSete(){
Random random = new Random();
/*=====ACTIVITY PLUS=======*/
int generated1_plus = random.nextInt(9);
int generated2_plus = random.nextInt(17 - 9) + 10;
int generated3_plus = random.nextInt(24 - 18) + 20;
/*Grupo de 7 números*/
String sevenGroup = String.valueOf(generated1_plus
+ " - "
+ generated2_plus
+ " - "
+ generated3_plus);
//Resultado
setSecond(sevenGroup);
}
public String getSecond() {
return second;
}
public void setSecond(String second) {
this.second = second;
}
How can I do?
Are these groups 0-9 and 9-17? Or would it be 0-8 and 9-17? Or still 0-9 and 10-17? Also, you speak 18-25, but your code generates 20-25. Your code also generates 10-18. I can’t understand what logic you want for those numerical ranges and without that you can’t answer the question.
– Victor Stafusa
So I tried to make a "scheme" so that it generates any number up to 18... then this 17 - 9 = 8(it generates from 0 to 8) and then add + 10 giving a value of 10 up... only that wanted some form that determines my minimum and that I can get out of this formula... something that is (start between x and y) as the example
– Nathan
Yes, but why 18? I’m not asking about the formula, I’m asking what are the desired tracks. Knowing the tracks, finding the formula is easy.
– Victor Stafusa
is why I wanted 18 anyway for this
– Nathan