Random Number Generation in Weblogic

Posted: Thursday, November 22, 2012 by జగదేశ్ in Labels: ,

The Generation of Random Number are done by using Math.random() or SecureRandom. The Source for generating the random numbers can be configured in such a way that they can depend on the Operating System. Java uses its own source for generating the Random numbers but for better random numbers, the source for generating the random numbers can assigned to the underlying operating System hardware Signals which are generated from the interactions from the network ,keyboard and other devices.

In RHEL, there are 2 files available that help in generating the Random numbers

The Random number generator uses hardware noises for generating the random numbers. The noise generated by the hardware is thus stored inside the entropy pool. The generator also has the information on how much bits of information is available in the entropy pool.

From using this entropy pool, the random numbers are generated.

The /dev/random will only return random date within the estimated number of bits of noise in the
entropy pool but one issue with this is the /dev/random will be blocked until additional noise is generated or bits available in the entropy pool. If no bits are available in the entropy pool, the /dev/random will be blocked.

The /dev/urandom will return as much data requested.

If your system does not have /dev/random and  /dev/urandom created  already,  they  can be created with the following  commands:

               mknod -m 644 /dev/random c 1 8
               mknod -m 644 /dev/urandom c 1 9
               chown root:root /dev/random /dev/urandom

The library used for random number generation in Sun's JVM relies on /dev/random by default for Linux platforms. For configuring the random number generation with Weblogic,

Check if /dev/random works fine
head -n 1 /dev/random

If the command returns immediately, you can use /dev/random as the default generator for SUN's JVM. If the command does not return immediately, use these steps to configure the JVM to use/dev/urandom .This can be configured as
-Djava.security.egd=file:/dev/./urandom and added to the Weblogic startup script

Happy learning