Hi,
Thank you for your enquiry.
The easiest way to produce a random integer within a certain range is to simply multiply the Math.random() function (which produces a random number between 0 and 1) by the maximum value in your range. So, for example, if you wanted to generate a random x co-ordinate between 0 and 800 (the width of your page), you would use the following script:
Code:
x = Math.random()*800
As this can produce numbers with lots of decimal places you may wish to round down or round up the value to the nearest whole number. To do this, simply use the following code:
Code:
x = Math.round(Math.random()*800)
Please note that the SetPosition() function dictates the mid-point of the target object, so you may wish to take the width of the object into account when generating the random number. Otherwise, your image may end up positioned too close to the edges of the page, truncating the image. The following script should ensure that the random number falls within the correct range:
Code:
pagewidth = 800 //change this value if your page is a different size
imagewidth = Image.GetWidth()
x = Math.round(Math.random()*(pagewidth-imagewidth))+(imagewidth/2)
Image.SetXPosition(x)
I hope this helps. Please do not hesitate to contact me if you have any further queries.
Kind regards,