How to read /dev/random in python

前端 未结 3 1999
无人共我
无人共我 2021-01-05 01:47

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.

3条回答
  •  情深已故
    2021-01-05 02:21

    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.

提交回复
热议问题