Random numbers in Linux can be generated from two special files, one/dev/urandom. The other is/dev/random. The principle of generating random numbers is to use the current system's entropy pool to calculate a fixed number of random bits, and then return these bits as a byte stream. Entropy pool is the current system of environmental noise, entropy refers to a system of chaos, system noise can be evaluated through a number of parameters, such as the use of memory, the amount of files used, the number of different types of processes and so on. If the current ambient noise is not very intense or the current ambient noise is very small, such as when the first boot, and the current need for a large number of random bits, the random number generated by the random effect is not very good.
That's why there are two different kinds of files,/dev/urandom and/dev/random, which block the program when it doesn't produce a new random number, and the former doesn't (Ublock), and of course the random number effect is not good, This is not a good choice for applications such as encryption and decryption. /dev/random blocks the current program until a new random byte is generated based on the entropy pool, so using/dev/random is slower than generating a large number of random numbers using/dev/urandom.
The following is a simple test:
- [[email protected] dd]$ dd if=/dev/random of=random.dat bs=1024b count=1
- 0+1 Records in
- 0+1 Records out
- Bytes (+ B) copied, 0.000169 seconds, 757 kb/s
- [[email protected] dd]$ dd if=/dev/urandom of=random.dat bs=1024b count=1
- 1+0 Records in
- 1+0 Records out
- 524288 bytes (524 kB) copied, 0.091297 seconds, 5.7 MB/s
You can see that using/dev/random to generate random numbers is very slow, and the amount of production is very limited, of course, the/dev/urandom random effect is much better.
Random number file/dev/random/dev/urandom in Linux