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

2012/6/2

Random Numbers quesition

seal308 seal308

2012/6/2

#
Hi i'm new to greenfoot. I want to get random numbers between 85 and 95 But i'm not sure how. i know to get a random number between 0 and 90 it's like this Greenfoot.getRandomNumber(90); But i don't want that i want that range.
seal308 seal308

2012/6/2

#
I know i could say something like. Oh never mind i figured it out. ask for a random number between 0 and 10 so Greenfoot.getRandomNumber(10); Then add 85 to that random number. now range is between 85 and 95
danpost danpost

2012/6/2

#
Keep in mind, when you use 'Greenfoot.getRandomNumber(10)', you will get a number between 0 and 9, inclusive. That is, the number supplied is the range of numbers to take a random sample from (or the number of items to pick one out of). Starting at 0, the tenth item will be 9. Basically, what I am saying, is that if you are to include 95 as a valid return, you need to use 11 in the random number statement.
seal308 seal308

2012/6/2

#
k thx
You need to login to post a reply.