如何每天随机排列一个数组,每次用户重新加载页面时都会返回该数组

How to shuffle an array daily which is returned every time the user reloads page

我有一个数组,每次用户重新加载页面时都会通过 HTTP 请求获取该数组,我想每天随机播放它。

我希望这个数组每天都被打乱,并为所有用户整天保持相同的数组。随机顺序必须在用户第一次获取此数组时设置,并且必须对所有用户一整天都相同,从午夜开始,每次数组被请求获取时。

然后第二天,为所有用户再次洗牌,一整天但不同。等等。

这是我的随机播放功能:

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

}

我不太擅长算法(只是基础知识),欢迎提供一些帮助。

谢谢!

您的代码看起来可能是 JavaScript。如果是这样,请查看 Seeding the random number generator in Javascript 以获得种子随机数生成器。使用它来根据您当前的排序算法做出随机决定。

我建议从一个种子开始,该种子是一些固定垃圾字符串和当前日期的散列。这个每天会变一次,但是你昨天得到的信息不会泄露固定垃圾字符串的秘密。