random(a, b) returns a random number in the range
[a, b).
So what you probably want to do is take the number you got in your second example and use it as the index of your array.
PHP Code:
function onCreated(){
temp.images = { "test1", "test2" };
temp.random = temp.images[int(random(0, temp.images.size()))];
echo(temp.random);
}