Random Numbers
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Random Numbers
We are programming a game, and we have gotten to the point to where we need a ball to start moving at a random angle. How can we create a variable that will set itself to a minimum and maximum value and chose randomly in between?
Re: Random Numbers
have a look at random in the dictionary... especially the note at the bottom
To generate a random number between two integers, use a handler like this:
To generate a random number between two integers, use a handler like this:
Code: Select all
function randomInRange lowerLimit,upperLimit
return random(upperLimit - lowerLimit + 1) + lowerLimit - 1
end randomInRange
Re: Random Numbers
Hi.
What Dixie said.
And another way, a little easier to understand. If you wanted a number between, say, 100 and 150:
put random(50) + 100
Craig Newman
EDIT: However simple to understand, it does preclude 100. So if a strict, fully inclusive range is required, a little tweaking is needed.
What Dixie said.
And another way, a little easier to understand. If you wanted a number between, say, 100 and 150:
put random(50) + 100
Craig Newman
EDIT: However simple to understand, it does preclude 100. So if a strict, fully inclusive range is required, a little tweaking is needed.