Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I find two words in /dev/random using terminal? I tried dd if=/dev/random bs=2 && ( grep 'foo' || grep 'woo' ) but did not work: what is wrong?

share|improve this question
1  
from what I understood here: en.wikipedia.org/wiki//dev/random /dev/random generates random numbers, no words. maybe I got your question wrong? – user4711 Sep 25 '12 at 15:36
1  
There's a chance that a sequence of random bytes output by /dev/random could happen to form a string of ASCII or Unicode encoded text. – LawrenceC Sep 25 '12 at 15:40
    
This sounds like a case of the XY problem. What exactly are you trying to do here? Why do you need to search in /dev/random/? – terdon Sep 25 '12 at 16:25
1  
This question definitely requires a purpose -- finding arbitrary text in an endless random stream is nearly pointless unless you're trying to measure entropy (poorly) or something. – mikebabcock Sep 25 '12 at 17:23

grep -E '(foo|woo)' /dev/random should work, but it might be a long time (nearly forever) before you get those words from /dev/random.

With /dev/urandom you might have better luck, but still not very likely to happen.

Here's an example

$ dd bs=1024 count=100 if=/dev/urandom \
     | grep --binary-files=text -E 'AB|CD' \
     | tr -d '\000-\040'
100+0 records in
100+0 records out
à░,½BRπ╛$▄7¼+=r╠▌öBr95Ü@4ëîΩå«¥*╩╜╪╚▓OQ2╪Hª-┌█H$_½Yz/d·D┘═e|M┌■äφ╧F}<G¿2╣┴»x>▄⌐ùY╓│÷¡ç½;▀A└r╫½╞ë═m█ìα_ܵIé+q₧⌐ç╨√╛ºû{√╬│τ▓╟`░KÜRt∞≤aiwδ╫:Ñσwíö┘║╝N╣µ4╢m_«╩ΘΓ▌»câ ╪ÆΣªbI+AB┌⌐■_┴=åÉú°█╥╚╘á@δ╗⌡ï░rS¥ÉóU╣┬₧╞ÿ╔╥─}6R╚ßp]∞█├}L:─¢ñ+äª┤╒░▄Púj0íhf*Nà∙╥▒)d╠90,¥▀ÖE┬£r╦ⁿEF╛τ▀╥┐╛ƒ[9╓╖£╞ka▄¿E;┌τô4jτΩ⌠a[A<QGua5ù╞{LK╢▐û═yv╚°±&Z¢òP7^╬3D ╓╘y▐Mkª'Φ[}ΣuHÆπæ÷âì└«C<▐ß╙ε║î(π$CH▒yc╓É{≥f3(╔Ä9>FîR9~Φ"É$&/ƒ╠√▀k>⌡d;¢vcv«∙╩óÜ≈¡E╢:>╠Nl°CJAMÖ╥╠ßÑuÆ╤å√å{╪F╘╤¬╛Ev∞VwC%'[╝¡÷┤╚âΩ-╘5«>1▓b)f└φ╛wδ─⌡║3╝;í▐ßúⁿ¡&╞╨╖,~÷α¢ríôóH╩4Fú«:Γìφ√└╬²_╠±i╦£╒æ╤≤RFV╘┘┘0Θ/SåaQ_U($╡Dzq╞╜X╗╫lßFΓ¥÷~║┼╗µ[*┼≈¼º┘┘ís╬!é¢F>·W╨1J╘Ç
102400 bytes (102 kB) copied, 0.030347 seconds, 3.4 MB/s
share|improve this answer
2  
Also, since the output of /dev/random presumably includes byte-values corresponding to control-characters, you might want to filter those out after grep. I guess line lengths will average 255 but may be much longer. – RedGrittyBrick Sep 25 '12 at 16:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .