I have this function which makes my divs "slide" randomly every 3 seconds:
$(function () {
$('.fadein p:gt(0)').hide();
setInterval(function () {
var randomize = 1 + Math.floor(Math.random() * $('.fadein > p').length);
$('.fadein > p').fadeOut();
$('.fadein > :nth-child(' + randomize + ')').fadeIn();
}, 3000);
});
Here's the fiddle. The problem is that sometimes the slides are the same (as the random number generated is the same twice in a row). Can you help me creating some variable to store the last number generated so when the function calls Math.random(), if that number equals the last number generated it calls it again.