How do I change the Java source for random data?

Viewed 152

I'm trying to run code on a machine where /dev/random does not fill up quickly, and a java program I'm trying to use is hanging for lack of random numbers.

/dev/urandom produces "not as good" random numbers, but isn't blocking, and for this case I'd rather have less randomness and completing, than better randomness but never completing.

I tried passing this to java

-Djava.security.egd=file:/dev/./urandom

But it didn't fix anything("/dev/urandom" has problems in places, whereas "/dev/./urandom" works everywhere, which is why I used that path). Is there a way to do this?

I've now tried:

file:/dev/./urandom
file://dev/./urandom
file:///dev/./urandom
file:/dev/urandom
file://dev/urandom
file:///dev/urandom

none have worked

1 Answers

fileurl do require 2-3 forward slashes (according to RFC 1738):

-Djava.security.egd=file://dev/./urandom
-Djava.security.egd=file://dev/urandom
  • That system may only support the NativePRNG, but not the SHA1PRNG algorithm. Here it's explained: What java.security.egd option is for? To see what is available: cat /dev/./urandom and cat /dev/urandom. manpages state, that one can simply create the devices, in case they don't exist.

  • There still is the possibility, that Java code might do blocking I/O.

  • With containers this can also lead to performance issues:

The /dev/random device is a scarce shared system resource that Linux Container tenants likely have not realised they are sharing. When they all try to use it at the same time they are effectively causing a denial of service on each other.

Related