Include jquery at the top of your page and in head tab:
<script src="http://code.jquery.com/jquery-1.10.2.js" type="text/javascript"></script>
Try it again:
$(function(){
var image = new Array ();
image[0] = "http://placehold.it/20";
image[1] = "http://placehold.it/30";
image[2] = "http://placehold.it/40";
image[3] = "http://placehold.it/50";
var size = image.length
var x = Math.floor(size*Math.random())
$('#random').attr('src',image[x]);
})