Last week, I spent some time learning about random number generators and entropy pooling. Suppose you're in a Linux machine and you generate a random number in C++: std::random_device rd; std::uniform_int_distribution<int> dist(1, 10); dist(rd); But what does this do under the hood? std::random_device gives you a true random number and it pretty opaque. You don't really know exactly what it is, what it's going to do, or how efficient it will be. You don't even know if it can actually be acquired -- it might throw an exception when you attempt to create it. If you look at the libc++ code for std::random_device, it's just a thin wrapper over std::fopen("/dev/urandom"). So each time you create a std::random_device you are getting a filesystem handle and whenever you read from it, you are simply making a system call. When using GCC on Linux, std::random_device will try to use Intel's RDRAND instruction. RDRAND has a single entropy source and provides a stream of entropy data as zeros and ones. It is essentially a hardware circuit which jumps between 0 and 1 based on thermal noise fluctuations within the CPU. On Linux, the root of all randomness is something called the kernel entropy pool. This entropy pool is used in two ways: random numbers are generated from it and it is replenished with entropy by the kernel. When random numbers are generated from the pool the entropy of the pool is diminished, as the person receiving the random number has some information about the pool itself. You can even check a rough estimate of the number of bits of entropy in the pool with this command: cat /proc/sys/kernel/random/entropy_avail Hope this was useful, I might write a bit more in detail about this as I found it super intriguing!
Great! I thought about it a while ago and here you talked about it. Law of Attraction 🧲
256 for me.. This is a great post, commenting for others to see this : )
Research Intern @AIISC | Mentee @sktime | Sophomore @NIT-A
7moHave you checked out how they generate random numbers from lava lamps? If you haven't, you should watch it on YouTube, it's wonderful