Random number
in
Programming Questions
•
6 months ago
Hello everybody. I have coordinates for the position of an image stored in 4 different if's so it can appear in 4 different positions. What I want to do is to create a random number so it shows what's inside just one if.
The problem here is that random() generates lots of numbers and I only need the first one it generates.
Here's what I have.
But it shows the image in the 4 different positions every frame when running. How can I get it to show the image at just one position?
The problem here is that random() generates lots of numbers and I only need the first one it generates.
Here's what I have.
- int posXRandomItem=0;
- int posYRandomItem=0;
- int randomItem = (int) random(4);
- if (randomItem==1){
- posXRandomItem=40;
posYRandomItem=120; - }
- if (randomItem==2){
- posXRandomItem=200;
posYRandomItem=120; - }
- if (randomItem==3){
- posXRandomItem=360;
posYRandomItem=120; - }
- if (randomItem==4){
- posXRandomItem=520;
posYRandomItem=120; - }
- image(itemJustice, posXRandomItem, posYRandomItem);
But it shows the image in the 4 different positions every frame when running. How can I get it to show the image at just one position?
1