var images = [ { probability: .4, url: "venus.png"}, { probability: .3, url: "funnyvenus.png"}, ]; images.sort(function (a, b) { return a.probability - b.probability; }); function getImageUrl(images) { var rand = Math.random(); var sum = 0; for(var i=0; i < images.length; i++) { sum += images[i].probability; if(rand <= sum ) { return images[i]; } } }