How do we generate numbers that honor a normal distribution?
-
Show this thread
-
A normal distribution is a super common statistical distribution, it describes the distribution of lots of phenomena and the central limit theorem says that basically any distribution is secretly just one step removed from the normal distribution.
1 reply 1 retweet 21 likesShow this thread -
That probably didn't make any sense. Here's a Wikipedia page that also won't make much sense: https://en.wikipedia.org/wiki/Normal_distribution … . It especially doesn't make sense that those totally differently looking lines are supposed to be "the same". That's ok though.
1 reply 1 retweet 22 likesShow this thread -
It's ok because STATISTICS DOESN'T MAKE SENSE. They work really well, but if you think about them for too long and too deeply, you fall into a transcendent state. That's also how we know that statistics are pure science. Anyway, back to the topic ...
2 replies 20 retweets 114 likesShow this thread -
A cool, though not common any more, way to generate normally distributed numbers is called the Box-Muller transform, https://en.wikipedia.org/wiki/Box–Muller_transform …, and it combines the "Just throw the bad crap away" (aka rejection sampling) and two-dimensional approaches we've seen already.
1 reply 2 retweets 34 likesShow this thread -
With Box-Muller, we choose two random values, between -2^^31 and 2^^31 say, we plot them as x and y on a two dimensional plane. If (x,y) lies within the circle of radius size 2^^31, we keep the point, otherwise we go again. r is the distance from the origin to (x, y) squared.
1 reply 0 retweets 21 likesShow this thread -
Here's a picture from Wikipedia, but basically we're throwing darts at a square and if they land in a circle we're good. It's amazing how much low-level stuff is dumb-as-rocks.pic.twitter.com/pQ97dvdD8x
2 replies 3 retweets 54 likesShow this thread -
O.k. some parting thoughts before ending this thread. First, if you need to generate random numbers in constant time, or exotic distributions, get super deep into this stuff. There are seriously rough weeds to tackle.
2 replies 1 retweet 27 likesShow this thread -
Second: if you find yourself building a whole RNG, it's really very hard, again, get deep in the weeds and learn about DRBGs, fork-safety, thread-safety, /dev/urandom, getrandom() and so on. Avoid if you can!
4 replies 0 retweets 28 likesShow this thread -
Replying to @colmmacc
Are you saying to avoid urandom? I use it for my RPi passphrase generator and it's great https://penfold.fr
1 reply 0 retweets 0 likes
Using urandom is a great default. If you don't need extreme performance, and you can rely on the kernel being up to date and patched, it's a great way to go.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.