This site requires JavaScript, please enable it in your browser!
Greenfoot
Username
Password
Remember Me?
Sign Up, Lost Password
Activity
About
Documentation
Download
Discuss
Scenarios
bonana
wrote ...
2013/1/24
random number between x and y
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
2013/1/24
#
Okay, got it. It's
x + Greenfoot.getRandomNumber(y)
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
2013/1/24
#
Okay, thanks for the correction.
You need to login to post a reply.
X