TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Random with care

89 pointsby dhotsonover 7 years ago

10 comments

saosebastiaoover 7 years ago
Great article, lots of things I&#x27;ve ranted about in the past, and lots of things I&#x27;ve never considered.<p>An apocryphal story from a former finance professor who taught me about MCMC: One of his former colleagues was working for a hedge fund in commodity futures markets, and he had developed a monte carlo model for trading in a very specific market that was working exceptionally well. Then one day it stopped working so well...returns cut by 1&#x2F;2 of their original level. It wasn&#x27;t a gradual decline, but rather one day it was one level and then overnight that changed. He eventually got poached by a competing hedge fund working in the same exact markets, and he found out that the reason his returns declined was because one of the mathematicians at his new company had almost perfectly reverse engineered his model by guessing his RNG seed, conveniently a number in the name of his former hedge fund.
评论 #16081305 未加载
x1798DEover 7 years ago
In the example about picking a random 3-d vector, it seems like the &quot;draw components from a Gaussian distribution&quot; method is the most common, but I don&#x27;t really understand why you can&#x27;t just pick two angles ([0, pi) and [0, 2pi) respectively) from a uniform distribution and interpret those as spherical coordinates on a unit sphere.<p>Given that the &quot;draw from a Gaussian and normalize&quot; seems like the hard way to do it and also is the only one anyone is suggesting, I assume I&#x27;m missing something. Anyone know what the problem is?
评论 #16080923 未加载
评论 #16080939 未加载
评论 #16082185 未加载
评论 #16084076 未加载
评论 #16081043 未加载
评论 #16082982 未加载
JadeNBover 7 years ago
As with cryptography, it&#x27;s probably dangerous to &quot;roll your own random&quot; <i>if</i> the randomness matters. The author already mentions both the point about cryptography, and the dangers of plausibility arguments about randomness: an intuitively plausible way of picking a random point from a sphere doesn&#x27;t give a uniform distribution.<p>Playing around with distributions as the author does is surely fine if you just want to get something that &quot;feels right&quot;, but if the applications depend on precise randomness properties, then, for example, &quot;let&#x27;s just multiply these two PDFs&quot; is dangerous (not least because the result is almost guaranteed not to be a PDF, and may not even be normaliseable to one).<p>Although it surely won&#x27;t be applied for random f (no pun intended), the transformation from P(f(u) ≤ x) to P(u ≤ f^(-1)(x)) relies very much on f being (strictly, in order to have an inverse) increasing—so it&#x27;s even dangerous to use f(x) = x^2 if we don&#x27;t know that u is non-negative-valued.
评论 #16082647 未加载
jhallenworldover 7 years ago
It reminds me of this nice link on how to generate Gaussian from uniform, using Box-Muller transformation:<p><a href="http:&#x2F;&#x2F;www.design.caltech.edu&#x2F;erik&#x2F;Misc&#x2F;Gaussian.html" rel="nofollow">http:&#x2F;&#x2F;www.design.caltech.edu&#x2F;erik&#x2F;Misc&#x2F;Gaussian.html</a>
dredmorbiusover 7 years ago
I discovered through experimentation recently that GNU awk (gawk) takes only signed 32 bit values.<p>A loop of 10 million iterations of straight rand() output produces unique values only about 2% of the time -- the other 98% of values are repeated throughout the sequence. (This may be due to time-of-day as seed.)<p><pre><code> gawk &#x27;BEGIN {srand(); for (i=0;i&lt;10000000;i++) printf(&quot;%s\n&quot;, rand())}&#x27; | sort | uniq -c | wc -l </code></pre> The srand() feature appears to take in signed 32-bit values only -- that is, -2147483647 to 2147483648. If you require more than 4.2 billion distinct sequences, this might be something to keep in mind.<p>This information may be well documented, though I find it in neither the gawk manpage (yes, I&#x27;m aware FSF deprecates manpages, an idiotic move), nor the online gawk manual, linked below.<p>Again -- if you&#x27;re just playing around, this may not hurt you, but if you&#x27;re fond of gawk and think you can develop high-strength crypto or security code using it, you&#x27;re going to need to go beyond the built-ins at the very least.<p>Earlier: <a href="https:&#x2F;&#x2F;plus.google.com&#x2F;104092656004159577193&#x2F;posts&#x2F;exhAxhd4v2n" rel="nofollow">https:&#x2F;&#x2F;plus.google.com&#x2F;104092656004159577193&#x2F;posts&#x2F;exhAxhd4...</a>
adwhitover 7 years ago
&gt; [Tetris] simply shuffles a list of all 7 pieces, gives those to you in shuffled order, then shuffles them again to make a new list once it’s exhausted.<p>Interesting tidbit! So all the times I&#x27;ve furiously cursed at my gameboy because I swear the &#x27;I&#x27; is by far the rarest tetrimino and it hasn&#x27;t given me one for at least 20 turns... was just classic cognitive bias.
评论 #16087092 未加载
0xdeadbeefbabeover 7 years ago
&gt; If your random number generator has fewer than 226 bits of state, it can’t even generate every possible shuffling of a deck of cards!<p>Anyone know why?
评论 #16082707 未加载
gattrover 7 years ago
As for choosing random 3D directions with various distributions (and more), the Global Illumination Compendium [1] has a lot of useful formulas.<p>[1] <a href="https:&#x2F;&#x2F;people.cs.kuleuven.be&#x2F;~philip.dutre&#x2F;GI&#x2F;" rel="nofollow">https:&#x2F;&#x2F;people.cs.kuleuven.be&#x2F;~philip.dutre&#x2F;GI&#x2F;</a>
gmiller123456over 7 years ago
&quot;Random numbers should not be generated with a method chosen at random&quot; -- Donald Knuth
评论 #16082348 未加载
venuurover 7 years ago
The Just Simulate It principle is super practical. I once sat through a talk by a principal engineer who’s talk was based on that premise.