读取 /dev/urandom or /dev/random 生成随机数 - yanbin's Blog

读取 /dev/urandom or /dev/random 生成随机数

yanbin posted @ 2015年3月29日 19:28 in Programming with tags programming linux random , 13235 阅读
< /dev/urandom tr -dc A-NP-Za-kmnp-z2-9 | head -c 8
?获取一个 8 位的随机数,除了 0, 1, o,O, l 之外.
?
tr -dc a-z < /dev/urandom 从 /dev/urandom 读入数据并且把所有的小写字母输出。
-d, delete characters in SET1 (a-z);
-c, use the complement of SET1
一个删除,一个补全,最终的效果就是获得读入数据中的所有小写字母。
tr 是从标准输入读入数据,直到遇到 EOF 才会停止,但是 /dev/urandom 是没有 EOF 的。
head -c 8 的作用很明显,就是获得 tr 标准输出中的前 8 个字符,这样这条命令/程序,才可以退出。
?
节省熵池的方法, 生成了长度为 12 的随机数:
dd if=/dev/urandom bs=1 count=6 2> /dev/null | od -t x1 | tee test | sed '2d;s/^0\+ //;s/ //g'
?
生成一个随机 MAC 地址, 节省熵池的方法:
dd if=/dev/urandom bs=1 count=6 2> /dev/null | od -t x1 | sed '2d;s/^0\+ //;s/ /:/g'
?
不建议使用的方法:
< /dev/urandom tr -dC a-f0-9 | head -c 12 | sed s/../\&:/g | head -c 17
?
/dev/urandom:u 是 unlocked 的意思.
/dev/urandom 是 /dev/random 的非阻塞副本。
/dev/random 是 Linux/Unix ?操作系统中的一个设备文件,用来作为随机数发生器/伪随机数发生器。
它允许程序访问来自设备驱动程序或其它来源的背景噪声,Linux是第一个以背景噪声产生真正的随机的实现。
?
在 Linux 系统上,有一个存储噪声的熵池,读取时 /dev/random 设备返回小于熵池字节总数的随机字节。
/dev/random 可生成高随机性的公钥一次性密码本。若熵池空了,对 /dev/random 的读操作将会被阻塞,直到收集到了足够的环境噪声为止[3]
这样的设计使得 /dev/random 是真正的随机数发生器,提供了最大可能的随机数据熵,建议在需要生成高强度的密钥时使用。
/dev/random 的一个副本是 /dev/urandom?("unlocked",非阻塞的随机数发生器[4]),它会重复使用熵池中的数据以产生伪随机数据。
这表示对/dev/urandom的读取操作不会产生阻塞,但其输出的熵可能小于 /dev/random 的。
它可以作为生成较低强度密码的伪随机数生成器,不建议用于生成高强度长期密码。

感谢 依云 教我用节省熵池的方法。

Avatar_small
mobogenie 说:
2017年1月22日 19:03

Really appreciate for your amazing article. Keep going on, good stuff. Thank you for this valuable information.

Avatar_small
Banggood 说:
2017年4月09日 23:37

Really appreciate for your amazing article. Keep going on, good stuff. Thank you for this valuable information.

Avatar_small
Songsterr 说:
2017年4月15日 18:28

Really appreciate for your amazing article. Keep going on, good stuff. Thank you for this valuable information.

Avatar_small
fast pokemap 说:
2017年4月22日 15:14

Valuable information! Looking forward to seeing your notes posted. Thank you for sharing the nice article. Good to see your article.

Avatar_small
Avito.ma 说:
2017年5月11日 01:04

This is a very interesting web page and I have enjoyed reading many of the articles and posts contained on the website, keep up the good work and hope to read some more interesting content in the future.

Avatar_small
fetlife apk 说:
2017年5月21日 17:42

Valuable information! Looking fo

Avatar_small
hotmail login 说:
2017年7月17日 14:21

The article you have shared here very good. This is really interesting information for me. Thanks for sharing!

Avatar_small
free hotmail login 说:
2017年7月17日 14:22

Thanks for sharing this great. Keep sharing more useful and conspicuous stuff like this. Thank you so much

Avatar_small
slader 说:
2017年7月23日 16:36

Valuable information! Looking forward to seeing your notes posted. The information you have posted is very useful. Keep going on, good stuff. Thank you for this valuable information. I have enjoyed reading many of the articles and posts contained on the website, keep up the good work and hope to read some more interesting content in the future.

Avatar_small
rediffmail 说:
2017年7月25日 01:17

This is a very interesting web page and I have enjoyed reading many of the articles and posts contained on the website, keep up the good work and hope to read some more interesting content in the future.

Avatar_small
Ace2three 说:
2017年7月25日 10:55

The sites you have referred were good. This is a great article, that I really enjoyed reading. Thanks for sharing.

Avatar_small
symbolab 说:
2017年7月30日 21:36


Valuable? ?information!? ?Looking? ?forward? ?to? ?seeing? ?your? ?notes? ?posted.? ?The? ?information? ?you? ?have
posted? ?is? ?very? ?useful.? ?Keep? ?going? ?on,? ?good? ?stuff.? ?Thank? ?you? ?for? ?this? ?valuable? ?information.? ?I? ?have
enjoyed? ?reading? ?many? ?of? ?the? ?articles? ?and? ?posts? ?contained? ?on? ?the? ?website,? ?keep? ?up? ?the? ?good
work? ?and? ?hope? ?to? ?read? ?some? ?more? ?interesting? ?content? ?in? ?the? ?future.

Avatar_small
chat avenue 说:
2017年8月01日 10:09

It is a great article. You will surely like this also because it is a great stuff, yeah it’s give us lots of interest and pleasure. Their opportunities are so fantastic and working style so speedy. Thank you for sharing the nice article.

Avatar_small
chat avenue 说:
2017年8月01日 20:33

It is a great article. You will surely like this also because it is a great stuff, yeah it’s give us lots of interest and pleasure. Their opportunities are so fantastic and working style so speedy. Thank you for sharing the nice article.

Avatar_small
Ace2three 说:
2017年8月02日 12:13

Good stuff, really superb. Because we can get more views through your site. So please keep update like this.

Avatar_small
chat avenue 说:
2017年8月03日 23:32

http://ssapptricks.com/chat-avenue/ Valuable information! Looking forward to seeing your notes posted. The information you have posted is very useful. Keep going on, good stuff. Thank you for this valuable information.

Avatar_small
bancolombia 说:
2017年8月11日 15:44


Valuable? ?information!? ?Looking? ?forward? ?to? ?seeing? ?your? ?notes? ?posted.? ?The? ?information? ?you? ?have
posted? ?is? ?very? ?useful.? ?Keep? ?going? ?on,? ?good? ?stuff.? ?Thank? ?you? ?for? ?this? ?valuable? ?information.? ?I? ?have
enjoyed? ?reading? ?many? ?of? ?the? ?articles? ?and? ?posts? ?contained? ?on? ?the? ?website,? ?keep? ?up? ?the? ?good
work? ?and? ?hope? ?to? ?read? ?some? ?more? ?interesting? ?content? ?in? ?the? ?future.

Avatar_small
tipsforapps 说:
2017年8月18日 22:13

Valuable information! Looking forward to seeing your notes posted. Thank you for sharing the nice article. Good to see your article.

Avatar_small
free hotmail login 说:
2017年8月23日 16:16

This is great, That's a great website, it really is what I was looking for, thank you for sharing!

Avatar_small
tv online streaming 说:
2017年9月20日 21:52

Good stuff, really superb. Because we can get more views through your site. So please keep update like this.

Avatar_small
lolnexus 说:
2017年9月20日 23:52

It is a great article. You will surely like this also because it is a great stuff, yeah it’s give us lots of interest and pleasure. Their opportunities are so fantastic and working style so speedy. Thank you for sharing the nice article.

Avatar_small
lolnexus 说:
2017年9月27日 15:06

I have enjoyed reading many of the articles and posts contained on the website, keep up the good work and hope to read some more interesting content in the future.

Avatar_small
shelly 说:
2017年10月16日 18:38

Info nya mantap gan..
Jangan lupa kunjungi blog kami juga ya gan

Agen Bola Online
Casino Online
Judi Online
Agen Togel
Bandar Bola

Avatar_small
lolnexus 说:
2017年10月19日 19:05

Valuable information! Looking forward to seeing your notes posted. The information you have posted is very useful. Keep going on, good stuff. Thank you for this valuable information.

Avatar_small
pokemesh 说:
2017年10月22日 14:18

Thank you for this valuable information. I have enjoyed reading many of the articles and posts contained on the website, keep up the good work and hope to read some more interesting content in the future

Avatar_small
Tamilrockers 说:
2017年11月16日 17:25

This is great, That's a great website
https://tamilrockers.org.in/julie-2-tamilrockers/
https://tamilgun.org.in/julie-2-tamilgun/
https://tamilyogi.org.in/julie-2-tamilyogi/
https://tamilrockrs.org/julie-2-tamilrockers/
https://hdvideosong.org/julie-2-video-songs/
https://xmovies8.net.in/tumhari-sulu-xmovies8/
https://khatrimaza.net.in/dashakriya-khatrimaza/
https://khatrimaza.net.in/dil-jo-na-keh-saka-khatrimaza/
https://khatrimaza.net.in/tumhari-sulu-khatrimaza/
https://xmovies8.net.in/dashakriya-xmovies8/
https://xmovies8.net.in/dil-jo-na-keh-saka-xmovies8/
https://tamilrockrs.org/en-aaloda-seruppa-kaanom-tamilrockers/
https://tamilgun.org.in/en-aaloda-seruppa-kaanom-tamilgun/
https://tamilrockers.org.in/en-aaloda-seruppa-kaanom-tamilrockers/
https://tamilyogi.org.in/en-aaloda-seruppa-kaanom-tamilyogi/
https://tamilgun.org.in/theeran-adhigaram-ondru-tamilgun/
https://tamilyogi.org.in/theeran-adhigaram-ondru-tamilyogi/
https://tamilrockrs.org/theeran-adhigaram-ondru-tamilrockers/
https://tamilrockers.org.in/theeran-adhigaram-ondru-tamilrockers/

Avatar_small
jio4gvoice 说:
2017年11月23日 01:55

I really like reading through a post that can make people think. Also, many thanks for permitting me to comment!

Avatar_small
yareel 说:
2017年12月18日 19:54

Valuable information! Looking forward to seeing your notes posted. The information you have posted is very useful. Keep going on, good stuff. Thank you for this valuable information.

Avatar_small
vid2mp3 说:
2017年12月18日 19:56

I'm very happy to find this page. I need to to thank you for your time due to this fantastic read!! I definitely enjoyed every part of it and I have you book marked to see new stuff on your web site.

Avatar_small
khatrimaza 说:
2017年12月21日 19:14

This is the right site for everyone who would like to find out about this topic. You realize so much its almost tough to argue with you (not that I actually would want to…HaHa). You definitely put a fresh spin on a topic which has been discussed for ages. Wonderful stuff, just great!

Avatar_small
mod apk game 说:
2017年12月25日 01:30

I hope that it does not disappoint me as much as this particular one. I mean, I know it was my choice to read

Avatar_small
adbfire 说:
2018年1月09日 01:45

Thanks a lot for sharing this informative blog. I am new to this field, and thus i am hoping for the similar post so that i can enhance my knowledge. Thank you.

Avatar_small
jio Cinema 说:
2018年2月01日 19:26

This is very nice post.Awesome keep sharing.

Avatar_small
viper for android do 说:
2018年3月26日 15:14

I found your post so interesting.

Avatar_small
Assignment help 说:
2018年10月06日 17:24

Students Assignment Help provides the services of customer psychology assignment help to the students.All Assignment Help is an online Assignment Help and assignment writing service offering expert assignment help.Hire Australian,US assignment writing experts.

Avatar_small
mobile price in bd 说:
2018年10月08日 09:56

thank you, brother, its good information

Avatar_small
Assignment help 说:
2018年10月12日 17:19

We have a strict quality control unit. They scrutinize the solutions and assure us about the quality. We do not compromise with the quality. If we are not satisfied, we ask the writers to revise the assignment solutions.Expert assignment helpers of Allassignmenthelp are well efficient and capable of creating unique assignments for college or university students all across the globe

Avatar_small
samsung mobile price 说:
2018年10月18日 17:47

I am waiting for your next article

Avatar_small
Mark Carey 说:
2018年10月29日 18:52

For regular security and support regarding apple account theft, loss and reset please read the information below:

According to a survey conducted recently, 72% of apple accounts are insecure and vulnerable to theft. There is a strong chance your apple account is also one of them. But the working solution is here:

Softpro services provide all kind of password-related queries for Apple products. With 24x7 online support, they are best apple id reset service providers on board.

[24x7] Toll-Free number: 1844-797-8692

For free consultation and queries regarding your apple id, here is the direct link of their website:

http://softproserv.com/iforgot-apple-id-password/index.html

Avatar_small
Mark Carey 说:
2018年10月29日 18:55

Are you facing troubles regarding your Microsoft account security? Are ids getting hacked?
There are strong chances that your account is also insecure like 81% other accounts.
Softpro services provide all kind of password-related queries for Microsoft products. With 24x7 online support, they are best email and account live password reset service providers on board.
Call Now Toll-Free number: 1-844-797-8692

For free consultation and queries regarding your Microsoft account, here is the direct link of their website.

Avatar_small
visit errorcodesfixe 说:
2018年12月31日 17:53

Ethernet and internet both sometimes can make you confuse if you are not a frequent user of the internet. You may be well versed with both the ...

Avatar_small
oppo f9 full Specifi 说:
2019年2月20日 21:06

I am back your site for good tutorial

Avatar_small
8th class result 201 说:
2019年3月01日 18:23

Article writing isn’t the easiest thing to do, but you are good at it. I am glad you shared this information and I agree with the points you have made.

Avatar_small
daftar agen bola ter 说:
2019年3月27日 03:28

Kabar menggembirakan datang kepada para bettor bola lovers, karena telah hadir situs sbobet online terpercaya di Indonesia yakni daftarbolasport.

Avatar_small
daftar agen judi bol 说:
2019年3月27日 03:31

Kabar menggembirakan datang kepada para bettor bola lovers, karena telah hadir situs sbobet online terpercaya di Indonesia yakni daftarbolasport.

Avatar_small
agen judi bola onlin 说:
2019年3月31日 22:51

Bettingligafox.com merupakan agen judi bola online terpercaya memberikan kesempatan kepada anda untuk bergabung didalamnya dan menikmati segala fasilitas yang telah di sediakan. Dalam berpartisipasinya member untuk bermain taruhan judi bola di dalamnya, sehingga layanan yang kami miliki menjadi kepercayaan terhadap member.

Avatar_small
metropcsonline 说:
2019年4月08日 17:13

metropcs.online Thank you for sharing this information with us. It’s really very helpful MetroPCS Payment | Pay Bill Online & Offline

Avatar_small
metropcsonline 说:
2019年4月08日 17:14

Thank you for sharing this information with us. It’s really very helpful https://metropcs.online/

Avatar_small
directtv 说:
2019年4月16日 15:12

DIRECTV Internet | DTV Internet Bundles, Speed, Price, and Review Thank you for sharing! I hope you will continue to have great articles like this to share with everyone!!! DirecTV Now | DTV Now Channels, Package, and Reviews

Avatar_small
directtv 说:
2019年4月16日 15:12

Thank you for sharing! I hope you will continue to have great articles like this to share with everyone!!! https://directtv.mobi/

Avatar_small
best Kodi on Firesti 说:
2019年4月25日 01:38

Utilization of dissertation url pages aided by the cyberspace at the time you turned into simply talked about as part of your web page.

Avatar_small
boostmobile 说:
2019年5月06日 17:21

Hello world! It’s Really an amazing Knowledge!!! thanks for sharing Boost Mobile

Avatar_small
boostmobile 说:
2019年5月06日 17:21

It’s Really an amazing Knowledge!!! thanks for sharing https://boostmobile.cc/

Avatar_small
henry 说:
2019年5月21日 01:07

Once again, this writer has published an astonishing article. It's simply remarkable to see such amazing work being done on this site. I think this is history in making, and people will remember this writer for a long time.

Avatar_small
tracfone.club 说:
2019年5月21日 17:53

Thanks for sharing Wonderful tips!! All are informative tracfone.club

Avatar_small
kiran 说:
2019年5月24日 22:49

Excellent content and thank you so much for share your knowledge
For know more related details can you click on below activated links
laser hair removalIf you want to check details about skin details andtattoo removal and best skin clinic in hyderabad , hair transplantation in hyderabad and get more updates check here

Avatar_small
Cannabis 说:
2019年6月16日 01:46

I simply must tell you that you have written an excellent and unique article that I really enjoyed reading.? I’m fascinated by how well you laid out your material and presented your views.? Thank you.

Avatar_small
mpcsonline 说:
2019年6月18日 20:39

Metro PCS Plans | Shop New Phone Plans, Unlimited Data, Talk & Text
This article is very much helpful and i hope this will be an useful information for the needed one. Keep on updating these kinds of information Mpcs Online

Avatar_small
Link Alternatif Sbob 说:
2019年6月22日 18:39

terimakasih atas informasi yang bagus seperti ini

Avatar_small
cleaning company dub 说:
2019年7月31日 17:19

Thank you for another excellent article. Exactly where else could anybody get that kind of data in this kind of a perfect way of writing? I have a presentation subsequent week, and I am to the appear for such information and facts.

Avatar_small
KOKO 说:
2019年8月13日 18:09

hello,
Your Site is very nice, and it's very helping us this post is unique and interesting, thank you for sharing this awesome information. and visit our blog site also
Satta King

Avatar_small
KOKO 说:
2019年8月13日 18:10

hello,
Your Site is very nice, and it's very helping us this post is unique and interesting, thank you for sharing this awesome information. and visit our blog site also

https://sattakingdarbar.com/

Avatar_small
????? 说:
2019年8月22日 01:24

That'sthe motive selling you acceptable study prior to designing. It is additionally doable to put in writing much better placing on this.

Avatar_small
KOKO 说:
2019年8月24日 15:57

hello,
Your Site is very nice, and it's very helping us this post is unique and interesting, thank you for sharing this awesome information. and visit our blog site also
Satta King

Avatar_small
allindiajobs 说:
2019年8月30日 12:37

Hello Readers!!! Tired of searching for the latest government jobs, bank jobs? Free Job Alert 2019 – Latest Upcoming Govt Jobs 2019 | Railways, Banks, UPSC, SSC Then, Here is fantastic news for you. Here, We, Allinidajobs team will update all the latest Government notifications, Freshers Jobs, and Walkins. Most of the people are struggling to search for the perfect site to get valid information. Employment News 2019-2020 | Employment News Paper Updates Finally, you are in the right place to get all the related information about Bank Jobs, Walkins, IT Software Jobs in All over India. Along with the job notification, We will provide the Syllabus and Previous Papers for practice purpose. Moreover, Get all the results and admit card updates from our blog TN TRB Recruitment 2019 | 814 Computer Instructors Grade I Posts | Apply Online

MP Vyapam PVFT Syllabus 2019 – Madhya Pradesh Pre Veterinary & Fisheries Test 2019 Exam Pattern Nowadays many of the students who are just out of the colleges and others also showing their interest in Government Jobs and IT Jobs. But it is very difficult to get the job because many competitors are in the race to participate in the latest Recruitments and Fresher Walkins. So we advise the job seekers to bookmark this page to get further information. You can also find out state wise jobs, Admit cards, Results, iT Walkins, Syllabus and Previous Papers, etc. People can find all the information on only one page called Allindiajobs.in . Freshers can get the details of Internships and Off-campus drive updates.

Avatar_small
allindiajobs 说:
2019年8月30日 12:38

Hello Readers!!! Tired of searching for the latest government jobs, bank
jobs? Then, Here is fantastic news for you. Here, We, Allinidajobs team
will update all the latest Government notifications, Freshers Jobs, and
Walkins. Most of the people are struggling to search for the perfect
site to get valid information. Finally, you are in the right place to
get all the related information about Bank Jobs, Walkins, IT Software
Jobs in All over India. Along with the job notification, We will provide
the Syllabus and Previous Papers for practice purpose. Moreover, Get all
the results and admit card updates from our blog.

Nowadays many of the students who are just out of the colleges and
others also showing their interest in GOVERNMENT JOBS AND IT JOBS. But
it is very difficult to get the job because many competitors are in the
race to participate in the latest Recruitments and Fresher Walkins. So
we advise the job seekers to bookmark this page to get further
information. You can also find out state wise jobs, Admit cards,
Results, iT Walkins, Syllabus and Previous Papers, etc. People can find
all the information on only one page called Allindiajobs.in. Freshers
can get the details of Internships and Off-campus drive updates
https://www.allindiajobs.in/

Avatar_small
abovethefloor.net 说:
2019年9月03日 03:11

The looks definitely splendid. Everyone of these dwarf tips can be fabricated by using lots of records go through. I want everything you need noticeably.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter