I got 3 - 4 divs on a page where I want to randomize a single list of images everytime the page loads. In the below example this works fine, however I've found that sometimes you can end up with 3 of the same images or two of the same images. Is there a big of logic one can employ in order to avoid this?
HTML
<div class="wrap">
<div class="divide-img"></div>
<div class="divide-img"></div>
<div class="divide-img"></div>
</div>
jQuery:
$(document).ready(function() {
var images = ['http://lorempixel.com/400/200/sports/1', 'http://lorempixel.com/400/200/sports/2', 'http://lorempixel.com/400/200/sports/3', 'http://lorempixel.com/400/200/sports/4'];
$('.divide-img').each(function(){
$(this).css({'background-image': 'url(' + images[Math.floor(Math.random() * images.length)] + ')'});
});
});
Any help / guidance would be appreciated.