Not that random numbers are not random, but to set the css values you need a unit like pixels, percent, etc.
img.style.top = random1 + 'px';
img.style.left = random2 + 'px';
And for these CSS values to take effect, the elements must have a different position than static
img.style.position = 'absolute';
Fiddle
source
share