Hello everyone, I'm trying simply to select a random boolean value. I am working on a program where I need to either either increase or decrease the x position of an object by one. So I decided to use this nextBoolean technique. If the boolean is true, then the x position will increase by one. And if it's false, it should decrease by what. I can't for the life of me figure out where I'm going wrong. As you can see in the console, the x position ALWAYS increases by one each turn. Thank you so much for any help you may be able to give.
Here is my source code for reference:
while (time != 12) {
Random rd = new Random(); // creating Random object
randomizer = rd.nextBoolean();
if (randomizer = true) {
xPosition +=1;
}
else {
xPosition -=1;
}
System.out.println(xPosition);
time += 1;
}
Aucun commentaire:
Enregistrer un commentaire