Your question is vague. each image has fixed height and width, since they are not vector image. You can't get random height and width, but if you look for random number then it's a different topic. Take a look at this
JavaScript random() Method[
^]
And you have used image as background of each DIV. If so, you cannot set height or width to any of the image. You are going to set height and width for div. But, if you want to set your div height and width according to your images height and width, it would be different method that you are seeking for. The following code might help
<html>
<script>
function process(di) {
var imgurl = di.style.backgroundImage.replace(/^url\(\"|\"\)$/g, "");
var img = new Image();
img.onload=function () {
di.style.height=this.height;
di.style.width=this.width;
}
img.src = imgurl;
}
window.onload = function () {
var x=document.querySelectorAll(".nonsense")
for(var i=0;i<x.length; i++) {
process(x[i]);
}
};
</script>
<body>
<div class="nonsense" style="background-image:url(orange.png)" >ORANGE COLOR</div>
<div class="nonsense" style="background-image:url(red.png)" >red COLOR</div>
</body>
</html>