Random number file/dev/random/dev/urandom in Linux

Source: Internet
Author: User

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:

  1. [[email protected] dd]$ dd if=/dev/random of=random.dat bs=1024b count=1
  2. 0+1 Records in
  3. 0+1 Records out
  4. Bytes (+ B) copied, 0.000169 seconds, 757 kb/s
  5. [[email protected] dd]$ dd if=/dev/urandom of=random.dat bs=1024b count=1
  6. 1+0 Records in
  7. 1+0 Records out
  8. 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.

MORE: Http://zh.wikipedia.org/zh-cn//dev/random

http://blog.csdn.net/wind19/article/details/8085164

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.