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

2013/1/24

random number between x and y

bonana bonana

2013/1/24

#
I know how to get a random number between 0 and x but what I need is a random number between y and x. Whats the code for that?
bonana bonana

2013/1/24

#
Okay, got it. It's x + Greenfoot.getRandomNumber(y)
davmac davmac

2013/1/24

#
No, if y is the smaller number it's y + Greenfoot.getRandomNumber(x - y). If you want it to include x in the range, it's y + Greenfoot.getRandomNumber(x - y + 1).
bonana bonana

2013/1/24

#
Okay, thanks for the correction.
You need to login to post a reply.