获取两个给定值之间的可播种的随机整数

Get a random integer between two given values that is seedable

我试图在几个不同的设备上生成一个 1 到 25 之间的随机整数,但希望结果相同而不必通过网络发送它。

我想过使用 hours:minutes 的时间戳作为种子,但无法弄清楚如何获得使用种子且介于两个值之间的随机生成的数字。

我看过 this 但每当我尝试生成一个值时,它只会将种子作为字符串返回给我,即使我让它工作,我仍然需要应用种子到限制在两个值之间的随机生成器。

您链接的库中的示例 - 似乎有效(尽管我对其进行了编辑以将其限制在特定范围内)。

const randGeneratorFrom = seed => {
  const generator = new Math.seedrandom(seed)
  return (min, max) => Math.floor(generator() * max) + min
}

const now = new Date();
const seed = [now.getUTCHours(), now.getUTCMinutes()].join(':')
const rand = randGeneratorFrom(seed)

// results will be the same for the given hour:minute
console.info(seed)

console.info(rand(1, 25))
console.info(rand(1, 25))
console.info(rand(1, 25))
console.info(rand(1, 25)) 
<script src="//cdnjs.cloudflare.com/ajax/libs/seedrandom/3.0.1/seedrandom.min.js">
</script>