Question

I just want to use /dev/random or /dev/urandom in my code to generate random numbers. This application is going to be run on all linux flavors.If these device files are not present in /dev directory, my application fails.So these device files (/dev/random and /dev/urandom) are available in every linux flavour?

Était-ce utile?

La solution

These devices are created by the kernel at boot time. Mostly all GNU/Linux distros will have them BUT this is not always true, you can compile a kernel to not to have them, so there could be systems where you dont find them, so take care. You should always write code that handles this weird/nasty situations. However 99'99% of the systems you will run your program will have both files.

About the files, /dev/random generates its numbers collecting noise produced by the user and peripherals, the problem with it is that if the entropy pool is empty read() operations on it will block (unless the file had been opened with O_NONBLOCK). /dev/urandom is the regular pseudo random number generator but it is "non-blocking".

Since you are actually writing code, I will supposed that your program doesn't need much security-concerned development, so I will recommend you to use /dev/urandom so your program doesn't get stuck waiting for entropy on /dev/random. BUT if your program REALLY NEEDS SECURITY... well, never program your own security-concerned code unless you really, really, REALLY know what you are doing. Read about "side-channel attacks" for instance.

Good luck.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top