I read in a book that /dev/random
is like an infinite file, but when I set up the following codes to see what the content look like, it prints nothing.
It is outputting random bytes, not random lines. You see nothing until you get a newline, which will only happen every 256 bytes on average. The reason /dev/urandom
appears to work is simply that it operates faster. Wait longer, read less, or use /dev/urandom
.
FWIW, the preferred way of accessing this stream (or something like it) in a semi-portable way is os.urandom()
with open("/dev/random", 'rb') as f:
print repr(f.read(10))