basically, you want a list of image urls, and then you can use a common number to refer to each one.
it could working something like :
cardname2='<img src=' + JSON.stringify(randn2+'.jpg') + ' />';
sometext2.innerHTML = cardname2;
ps, i did the same thing once upon a time; see http://danml.com/pub/memory.htm
for a peek at how i did it a while back...
BROWSER STATS [% share]
(2013/12/12) IE7:0.3, IE8:7.5, IE11:4.3, IE9:4.6, IE10:7.8, FF:18, CH:43, SF:5.5, MOBILE:21.5