Two types of random number generators for Linux

Source: Internet
Author: User
Tags generator

Linux has two special device files /dev/random and /de/urandom, which are used to generate a random number.

  1. The random number generated by/dev/random is related to the state of the computer hardware currently in use, which improves security and is ideal for scenarios where the quality of random numbers is highly demanding. However, if the hardware status change is insufficient to provide enough information to the random number generator, the program that reads the random number generated by it will block and wait until there is enough hardware status changes to cause the data to be generated.

  2. /dev/urandom is also known as "Infinity" or "non-clogging" ("unlimited"[5]/non-blockingrandom source[4] the random number generator, which generates random numbers, is independent of the hardware state, so it is much faster than/dev/random . The result of testing on my laptop is that generating a random number of 160M size takes about a second

Generate files with random number generators that are all random numbers:

DD If=/dev/urandom of=/test/random bs=1024k count=10

Because the random number generator is limited in speed, if you want to use it to generate random numbers to test disk write performance, you can store random numbers in an intermediate file and then write to disk test performance.

compared to/dev/zero ,/dev/urandom generates data much more slowly, and the result of testing on my laptop is slow , and the results are as follows:

[Email protected]~]$ time DD If=/dev/zero of=/dev/nullbs=160m count=1

1+0 Records in

1+0 Records out

167772160 bytes (168 MB) copied, 1.28577 s, $ mb/s

Real 0m1.289s

User 0m0.000s

SYS 0m1.278s

[Email protected]~]$ time DD if=/dev/urandom of=/dev/nullbs=160m count=1

1+0 Records in

1+0 Records out

167772160 bytes (168 MB) copied, 23.488 s, 7.1 mb/s

Real 0m23.491s

User 0m0.000s

SYS 0m22.569s



Test the random number generator speed test results on my laptop machine as follows (for reference):

The box uses several different methods to generate a random number that fills the size of a 160M file, which takes about seconds.

[Email protected]~]$ time DD if=/dev/urandom of=/dev/nullbs=16m count=10

10+0 Records in

10+0 Records out

167772160 bytes (168 MB) copied, 24.4058 s, 6.9 mb/s

Real 0m24.409s

User 0m0.000s

SYS 0m24.177s

[Email protected]~]$ time DD if=/dev/urandom of=/dev/nullbs=16k count=10000

10000+0 Records in

10000+0 Records out

163840000 bytes (164 MB) copied, 24.9815 s, 6.6 mb/s

Real 0m24.982s

User 0m0.036s

SYS 0m24.685s

[Email protected]~]$ time DD if=/dev/urandom of=/dev/nullbs=160m count=1

1+0 Records in

1+0 Records out

167772160 bytes (168MB) copied, 25.9681 s, 6.5 MB/s

Real 0m25.971s

User 0m0.000s

SYS 0m25.694s





Two types of random number generators for Linux

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.