Quote: "Can somebody please explain the efficiency of randomly cycling numbers?"
Let's assume you allocate a range of 1000 numbers for your images, and that you have used 200 of them for images.
If you start looking for a free image at the start of the range, and if you haven't yet unloaded any existing images, you will carry out 200 checks against existing images before you finally find the free one.
Now if you start at a random point in your number range, the chances of finding a free image are 4 in 5 (or 800 out of 1000 if you prefer). Even if the image number is in use, there's a good chance that the next won't be. That's 1 or 2 checks to find a free image.
If you start looking from the last image you used, then everything will be just fine initially - you only carry out a check on the next number, find it's free, and then use it. When you get to the end of the range and start again from the beginning of the range, you'll start running through image numbers that you have previously used. Generally, we tend to load images in groups - for example 20 or 30 frames of an animated sprite, or images for a GUI - and won't unload them (maybe they last for the lifetime of the program). That means that when we hit the first image in that group we now have a run of image numbers to get past before there's a chance of finding a free image. That's generally 1 check to find a free image, but on occasions it will take more as you work through those runs.
The first method (starting from the beginning of the range) gets worst as you load more images.
The second method gives no real guarantees, but will tend to immediately return a free image if the ratio of images to free numbers is high.
The third method gives no guarantees either, and will also tend to immediately return a free image, but does have the problem of dealing with runs of images that will unpredictably give worst performance on occasion.
Generally the choice should be the random start point, but if you know that there are no runs of images and you delete every image over time, or if your range is effectively infinite (or 22,000,000 which is DBPro's limit on image ids IIRC), then pick the third. Never pick the first (although it's what I see posted most often

).
Or use my plug-in commands and don't worry about the method - it always returns the lowest number available in the range that you specify, and it's very quick compared to any of these methods.