Moving image randomly in certain area

Im trying to move an image on the screen when clicked but I don’t want it to go off the screen at all or down more and 50pixels from the bottom because that is where my “ground” image is. what I have right now is:

[lua]function shoot(event)
if event.phase == “began” then
bullsEye.x = math.random(0, display.contentWidth)
bullsEye.y = math.random(0, display.contentHeight)
end
return true
end[/lua]

what do I need to add to make sure it doesn’t go off the screen or below my “ground” image?

 add a - 50 on the end (display.contentHeight - 50)

However you will also need to consider the dimensions of your image, and your reference point as if your math.random were to give your the result of say “1” then your image will be right at the top and if your reference point is the centre of the image = half image actually seen.

To test out just plug in values instead of using math.random ( a trial and error approach to get your min and max, or think about the math problem to make a simple math calc before calling math.random)

T.

 add a - 50 on the end (display.contentHeight - 50)

However you will also need to consider the dimensions of your image, and your reference point as if your math.random were to give your the result of say “1” then your image will be right at the top and if your reference point is the centre of the image = half image actually seen.

To test out just plug in values instead of using math.random ( a trial and error approach to get your min and max, or think about the math problem to make a simple math calc before calling math.random)

T.