I have an array which is being get by a HTTP request every times the user reloads the page, and I want to shuffle it daily.
I want this array to be shuffled day by day and keep the same array the whole day, for all the users. The shuffle order has to be set the first time a user is getting this array and have to be the same for all users the whole day, beginning at midnight, every time the array is beign get by the request.
Then the next day, shuffle again for all users, the whole day but differently. And so on.
Here's my shuffle function:
function shuffle (array) {
let currentIndex = array.length; let randomIndex
// While there remain elements to shuffle...
while (currentIndex !== 0) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() / 10) * currentIndex)
currentIndex--;
// And swap it with the current element.
[array[currentIndex], array[randomIndex]] = [
array[randomIndex], array[currentIndex]]
}
return array
}
I'm not so good at algorithmic (only basics) and some help on this would be welcome.
Thanks !