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

2024/5/19

Random Number in range

S00pM4n S00pM4n

2024/5/19

#
how do i generate a random number between 10 and 20 for example
Super_Hippo Super_Hippo

2024/5/19

#
Try to use the “Greenfoot.getRandomNumber” method.
danpost danpost

2024/5/20

#
S00pM4n wrote...
how do i generate a random number between 10 and 20 for example
int min = 10; // must not be greater than max
int max = 20; // must not be less than min
int randNum = min+Greenfoot.getRandomNumber(max-min+1);
You need to login to post a reply.