I'm creating a rotating banner, and for this I use the random javascript that draws a position in the array and displays, this already works well, the problem is that sometimes it draws the same number at random and repeats what is being displayed , I want to make sure that the lottery is not repeated. I'm trying to do a routine for this but after a while the banners stop being displayed and the result is not legal.
I'm trying like this.
var app = angular.module('starter');
app.controller('BannerAnuncios', function($scope, $timeout){
var banners = ["Fernando", "Paiva", "Campos", "Luis", "Gomes"];
var count = banners.length;
var lastBanner = 0;
function rotationBanner(){
var i = Math.floor(Math.random() * count);
if(i != lastBanner){
$scope.banner = banners[i];
}else{
rotationBanner();
}
console.log(lastBanner);
console.log(i);
lastBanner = i;
$timeout(rotationBanner, 5000);
}
rotationBanner();
});