Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

If you ran the following, what would happen?

cat /dev/random > ~/randomFile # don't run

Would it be written until the drive runs out of space, or would the system see a problem with this and stop it (like with an infinite symlink loop)?

share|improve this question
3  
I just wanted to add that concatenating random into devices was worth a few hours of fun in my youth. The framebuffer and sound card resulted in noise and the disk drive required me to do a low level reformat... good times. –  Bob Roberts Feb 5 '13 at 16:40
    
OT: 'executable /dev/dsp? sounds like fun' –  sendmoreinfo Feb 5 '13 at 21:04
    
@BobRoberts I has similar adventures, with similar outcomes. I also used to ssh into colleagues' linux workstations and cat DTMF tones to the internal speaker, then play a busy tone, so it sounded like their PC was trying to FAX something out. Ah, good times. –  Tim Kennedy Feb 6 '13 at 15:59
    
@TimKennedy how do you do that? Is there a /dev/ice for the 30mm audio jack? –  tkbx Feb 6 '13 at 16:41
    
@tkbx well, i'm dating myself, but back in the day you could cat a file to /dev/audio, and if it was a sound file (.wav) it would get played. –  Tim Kennedy May 1 '13 at 15:24

1 Answer 1

up vote 16 down vote accepted

It writes until the disk is full (usually there is still some space reserved for the root user). But as the pool of random data is limited, this could take a while.

If you need a certain amount of random data, use dd. For 1MB:

dd if=/dev/random iflag=fullblock of=$HOME/randomFile bs=1M count=1

Other possibilities are mentioned in answers to a related question.

However, in almost all cases it is better to use /dev/urandom instead. It does not block if the kernel thinks that it get out of entropy. For better understanding, you can also read myths about /dev/urandom.

Installing haveged speeds up /dev/random and also provides more entropy to /dev/urandom.

EDIT: dd needs the fullblock option as /dev/random (in opposite of /dev/urandom) can return incomplete blocks if the entropy pool is empty.

If your dd does not support units, write them out:

dd if=/dev/random iflag=fullblock of=$HOME/randomFile bs=1048576 count=1
share|improve this answer
5  
100 MiB of high-quality random data is a bit much... you should get a few bytes to seed some high-quality pseudo random number generator, like the Mersenne twister. If the application is critical (in a cryptographic sense) you must go and read up on the matter, and perhaps hire an expert. –  vonbrand Feb 5 '13 at 14:52
3  
@vonbrand No, reading 100MB from /dev/urandom is fine, there's no reason not to do it. And do not use a Mersenne twister to do crypto. And don't use /dev/random on Linux. –  Gilles Feb 5 '13 at 21:46
2  
@jofel: No, the output of /dev/urandom is fine for cryptographic use. Do not use /dev/random. –  Thomas Pornin Feb 5 '13 at 22:12
    
@Gilles, maybe I'm loosing it... I agree with everything you say, ans can't see where I said anything different. –  vonbrand Feb 5 '13 at 22:13
    
@Gilles & vonbrand: Thanks for you comments, I improved my answer (now only 1MB in the example, /dev/urandom recommended). –  jofel Feb 6 '13 at 10:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.