This site requires JavaScript, please enable it in your browser!
Greenfoot back
Tlax
Tlax wrote ...

2021/11/21

getRandomNumber

Tlax Tlax

2021/11/21

#
hello, I have a couple actors. In the world void prepare are all my actors that need to spawn. The x variable is good, but for the y variable i want to have a randomnumber. So i made an int y=Greenfoot.getRandomNumber. Normally you put a number between the () and then the variable is between 0 and the number. But i want the number to be between 120-280. How do i do this ?
Tlax Tlax

2021/11/21

#
so i actually fixed it, but the problem now is that i have a couple actors which i want to spawn somewhere x is given but the y has to be variable. I do have int y = Greenfoot.getRandomNumber(160)+121; But if i type the y in for all the actors they get a randomnumber, but its the same for all the actors. I would like to have a different y for every actor
danpost danpost

2021/11/21

#
Tlax wrote...
But if i type the y in for all the actors they get a randomnumber, but its the same for all the actors. I would like to have a different y for every actor
Please provide the code in question (the more, the better).
You need to login to post a reply.