I'm currently using Java's RNG Random r = new Random()
, and having it generate a new integer between 0 and 5 in a while loop.
while (someBoolean == false) {
int i = r.nextInt(6);
....
}
What I would like to do, is to remove a number from the range (for instance, 4) so that the RNG still generates a new number between 0 and 5, excluding one of the values.
My current best bet is the following:
while (someBoolean == false) {
int i = r.nextInt(6);
if (i == removedInt) { continue; }
....
}
However I'm worried this could cause long runs in my code where the RNG is constantly returning a number that I don't want.
[For clarity; the number that is being returned is a column in a Connect4 grid, or 2D int array. The method is randomly placing moves in columns until a column fills up, at which point I no longer want to be able to play in that column. ]
Any help appreciated :)