I am working on a simple Bingo game that has randomized numbers. My main class (Bingo) is here:(note that I have more code that is not relevant to the problem)`
public class Bingo {
public static void main (String[] args) {
RandNum columnB = new RandNum();
columnB.max = 15;
columnB.randNum();
int b1 = columnB.row1;
int b2 = columnB.row2;
int b3 = columnB.row3;
int b4 = columnB.row4;
int b5 = columnB.row5;
RandNum columnI = new RandNum();
columnI.min = 16;
columnI.max = 30;
columnI.randNum();
int i1 = columnI.row1;
int i2 = columnI.row2;
int i3 = columnI.row3;
int i4 = columnI.row4;
int i5 = columnI.row5;
RandNum columnN = new RandNum();
columnN.min = 31;
columnN.max = 45;
columnN.randNum();
int n1 = columnN.row1;
int n2 = columnN.row2;
int n3 = columnN.row3;
int n4 = columnN.row4;
int n5 = columnN.row5;
RandNum columnG = new RandNum();
columnG.min = 46;
columnG.max = 60;
columnG.randNum();
int g1 = columnG.row1;
int g2 = columnG.row2;
int g3 = columnG.row3;
int g4 = columnG.row4;
int g5 = columnG.row5;
RandNum columnO = new RandNum();
columnO.min = 61;
columnO.max = 75;
columnO.randNum();
int o1 = columnO.row1;
int o2 = columnO.row2;
int o3 = columnO.row3;
int o4 = columnO.row4;
int o5 = columnO.row5;
}
}
My class that I am using to generate the random numbers:
public class RandNum {
int min = 1;
int max;
public void randNum() {
Random rn = new Random();
int row1 = rn.nextInt(max - min + 1) + min;
int row2 = rn.nextInt(max - min + 1) + min;
int row3 = rn.nextInt(max - min + 1) + min;
int row4 = rn.nextInt(max - min + 1) + min;
int row5 = rn.nextInt(max - min + 1) + min;
}
}
Now the issue is that I am trying to set my b1, b2, etc variables to the variable row1, etc. in the RandNum class. I know that I could just put it all in one class but this is a problem I have had multiple times so I'd like to solve it. Any help is much appreciated.