This week's book giveaway is in the Testing forum.We're giving away four copies of The Way of the Web Tester: A Beginner's Guide to Automating Tests and have Jonathan Rasmusson on-line!See this thread for details.
Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# random integers....

Brandi Love
Ranch Hand
Posts: 133
I need to generate a random integer between 25 and 60 for a game I'm writing. I used a while loop to check randomly generated numbers untill I came up with one, but it seems like there must be an easier way to do this. Anyone have any if there is?

Angel Dobbs-Sciortino
Ranch Hand
Posts: 101
Try doing % 36 on your random number and adding 25 to it.
Angel

Wayne L Johnson
Ranch Hand
Posts: 399
Try:

"Math.random()" will return random number between 0.0 and 1.0, exclusive. Multiplying by 36 will give you a number between 0.0 and 36.0. The cast turns that into an "int" between 0 and 35. Adding 25 to that will give you a value between 25 and 60, inclusive.