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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

How Do Computers Generate Random Numbers?

65 点作者 aryamansharda超过 4 年前

10 条评论

lsc36超过 4 年前
1. You don&#x27;t turn PRNG into &quot;true&quot; RNGs simply by picking seeds from environmental randomness. The seed is just the initial state, as long as the output is generated by a deterministic algorithm, by definition it&#x27;s a PRNG. At the very best you can make a CSPRNG, but not a &quot;true&quot; RNG.<p>2. The dice roll example is <i>not</i> uniform distribution, I think this is a common pitfall when generating random integers of a range. `randomNumber % 6` results in a slight bias towards 0 and 1, since 2^31 % 6 == 2, there are more numbers in the range [0, 2^31-1] that map to 0 and 1 than those that map to 2...5. To make it uniform, for example, you should always discard if `randomNumber &lt; 2` and regenerate another number for use.
评论 #24468171 未加载
评论 #24468995 未加载
评论 #24469005 未加载
评论 #24468031 未加载
jrnkntl超过 4 年前
Cloudflare has a fun solution to this involving lava lamps[0][1]<p>[0] <a href="https:&#x2F;&#x2F;blog.cloudflare.com&#x2F;randomness-101-lavarand-in-production&#x2F;" rel="nofollow">https:&#x2F;&#x2F;blog.cloudflare.com&#x2F;randomness-101-lavarand-in-produ...</a><p>[1] <a href="https:&#x2F;&#x2F;blog.cloudflare.com&#x2F;lavarand-in-production-the-nitty-gritty-technical-details&#x2F;" rel="nofollow">https:&#x2F;&#x2F;blog.cloudflare.com&#x2F;lavarand-in-production-the-nitty...</a>
shadowprofile77超过 4 年前
Just out of layman&#x27;s curiosity, what would be the problem or difficulty of somehow connecting a more compact type of radio telescope that detects some level of cosmic background radiation and hooking that up to a computer. Would this not be a guaranteed way of generating truly random numbers for any need flawlessly?<p>I know that serious radio telescopes cost way more than any random person could afford to pay but I&#x27;ve certainly seen plans for smaller DIY homemade models.
评论 #24467738 未加载
评论 #24467286 未加载
评论 #24467250 未加载
评论 #24468183 未加载
评论 #24468130 未加载
mywittyname超过 4 年前
The chart shows the distribution of &quot;10,000 dice rolls,&quot; yet each potential value, 1-6, has between 6000 and 7000 hits, indicating the true number of rolls to be between 36,000 and 42,000.
评论 #24466572 未加载
rurban超过 4 年前
The Mersenne-Twister approach should certainly not be studied anymore, even if some popular old libraries still use it. It fell long out of favor, is too slow, and not good enough.<p>Modern PRNG&#x27;s can be tested with Dieharder, TestU01 or STS and benchmarked. This article only talks about primitive old LCG&#x27;s (not any good one) or MT.
评论 #24467278 未加载
评论 #24468589 未加载
mschuetz超过 4 年前
My favourite is this one: <a href="https:&#x2F;&#x2F;preshing.com&#x2F;20121224&#x2F;how-to-generate-a-sequence-of-unique-random-integers&#x2F;" rel="nofollow">https:&#x2F;&#x2F;preshing.com&#x2F;20121224&#x2F;how-to-generate-a-sequence-of-...</a><p>* Creates a sequence of unique integers<p>* Uses prime numbers that are congruent to P = 3 (mod 4).<p>* A single iteration has noticable patterns but applying it twice already results in randomness that is sufficiently good for many use cases.<p>* It is &quot;embarrassingly parallel&quot;, a simple mapping of randomValue = randomize(i). You can calculate unique and deterministic random numbers from input i in parallel threads with no sync between threads.<p>* Since it is a unique mapping of i to r, you can use it to shuffle data sets virtually instantly. Take the index of a value in the original array, and use it to compute the target index in the shuffled array.<p>* I&#x27;ve used it to shuffle up to 800 million items per second on a GPU, including the time it took to transfer the data from RAM to GPU. So without the IO, you could probably shuffle billions of values per second, probably mostly bound by GPU bandwidth. E.g., 700GB&#x2F;s and each item is 70 bytes -&gt; could perhabs shuffle 10 billion items per second.
cm2187超过 4 年前
Is a hardware random number generator that would use environment or electrical sensors to generate noise expensive or hard to manufacture? I would assume this should be part of any standard motherboard given the importance of cryptography. Or does it create an attack vector?
评论 #24468441 未加载
评论 #24469001 未加载
评论 #24468523 未加载
ImaCake超过 4 年前
For those interested, one can get from a uniform distribution to pretty much any defined statistical distribution using just the uniform random number generator and the inverse cumulative distribution function of the desired random distribution. A useful trick for non-standard distributions with no function available in your prefered language.<p>Example from matlab: <a href="https:&#x2F;&#x2F;www.mathworks.com&#x2F;help&#x2F;stats&#x2F;generate-random-numbers-using-the-uniform-distribution-inversion-method.html" rel="nofollow">https:&#x2F;&#x2F;www.mathworks.com&#x2F;help&#x2F;stats&#x2F;generate-random-numbers...</a>
johnatwork超过 4 年前
Roll20 has an interesting way of generating random numbers as well - <a href="https:&#x2F;&#x2F;wiki.roll20.net&#x2F;QuantumRoll" rel="nofollow">https:&#x2F;&#x2F;wiki.roll20.net&#x2F;QuantumRoll</a>
IIAOPSW超过 4 年前
My personal favorite RNG is the logistical map. x_{n+1} = 4x_n(1-x_n). There is no hidden seed beyond the current output. Thus if you have a scientific calculator that lets you refer to the value on screen then you can rig it into an RNG. Seeing a simple, non-programmable machine &quot;misbehave&quot; and act random melts my mind a little.
评论 #24467829 未加载
评论 #24468937 未加载
评论 #24467797 未加载