Could be something like this:
Code:
//inside your i loop
...
var root=document.getElementById('mydiv'+i);//the node where to append the image
var pic=document.createElement('img');
var att=[
['width',img_width],['height',img_height],['src','./images/'+img_rnd[i]]
]
for(var j=0;j<att.length;j++){
pic.setAttribute(att[j][0],att[j][1]);
}
var css=[
['position','absolute'],['zIndex',1],['left',x[i]+'px'],['top',y[i]+'px']
]
for(var j=0;j<css.length;j++){
pic.style[css[j][0],css[j][1]];
}
...
root.appendChild(pic);