TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

How to Generate a Sequence of Unique Random Integers (2012)

4 点作者 vince14超过 4 年前

1 comment

ChrisLomont超过 4 年前
Use any period 2^32 PRNG, which can easily be done with 4 bytes of storage. He used 8.<p>A simple LCG is of the form<p>seed &lt;- A*seed + B<p>Start with any seed, in 32 bit unsigned int, assume 32 bit wrapping like in C&#x2F;C++, etc. (or do mod yourself), pick good A and B, and away you go.<p>The Hull–Dobell Theorem tells you how to pick A and B for this size m=2^32: A and B are both odd and larger than 1 and A-1 is divisible by 4.<p>Finding nice A and B is a bit tricky - in which case look online for good choices or related theory.<p>Of course, a LCG may not be as random as you like. In that case one of the PCG variants solve the problem elegantly.