You could filter pages removing current value and only after that select random element.
If the one you pick is the same as the previous one, pick a new one:
const pages = [1, 2, 3, 4, 5];
const random = Math.floor(Math.random() * pages.length);
console.log(pages[random]);
let random2;
// Pick a new one:
while (random == ( random2 = Math.floor(Math.random() * pages.length)));
This assumes every value in the array is different, so it just cares that the two indexes (random and random2) are different.