Better seeds than time(0)?

前端 未结 11 1829
挽巷
挽巷 2021-01-02 08:06

I understand that time(0) is commonly using for seeding random number generators and that it only becomes a problem when the program is being run more than once per second.

11条回答
  •  礼貌的吻别
    2021-01-02 08:57

    On unix systems, you could take a few bytes from /dev/random as a seed for your RNG. /dev/random is supposed to be very good random, using the different entropy sources available on a PC. Of course, this is completely implementation-dependent.

    One case in which this could be useful is for cryptographic applications, since time(0) is relatively easy to guess.

提交回复
热议问题