The following code should produce random numbers between 0..2^5-1: import java.math.BigInteger; import java.security.SecureRandom; class RndTest { public static void main(String[] args) { SecureRandom rnd = new SecureRandom(); for (int i = 0; i < 10; i++) System.out.print(new BigInteger(5,rnd) + " "); } } [ben@localhost junit]$ java -version java version "1.4.2" gij (GNU libgcj) version 4.0.0 20050519 (Red Hat 4.0.0-8) [ben@localhost src]$ java RndTest 0 31 12 21 21 16 8 24 15 20 [ben@localhost src]$ java RndTest 0 31 12 21 21 16 8 24 15 20 [ben@localhost src]$ java -Djava.security.egd=file:/dev/random RndTest 0 31 12 21 21 16 8 24 15 20 [brh@jupiter ~]$ java -version java version "1.4.2" gij (GNU libgcj) version 4.0.1 20050727 (Red Hat 4.0.1-5) Copyright (C) 2005 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. [brh@jupiter ~]$ java RndTest 0 31 12 21 21 16 8 24 15 20 [brh@jupiter ~]$ java RndTest 0 31 12 21 21 16 8 24 15 20 In addition the following fails (one would expect an 8): import java.math.BigInteger; import java.security.SecureRandom; public class BigIntTest { public static void main(String[] args) { System.out.println(BigInteger.probablePrime(8,new SecureRandom()).bitLength()); } } [ben@localhost junit]$ java -version java version "1.4.2" gij (GNU libgcj) version 4.0.0 20050519 (Red Hat 4.0.0-8) [ben@localhost ~]$ java BigIntTest 2 [ben@localhost ~]$ java BigIntTest 2 See also: http://forums.java.sun.com/thread.jspa?messageID=3960085
This is related to PR 24481.
Confirmed for the GNU Classpath CVS version as of Thu Jan 12 18:47:25 CET 2006. On each start, we print the same sequence of numbers, when Sun's jre each time prints the different sequence of numbers.
*** Bug 27111 has been marked as a duplicate of this bug. ***
Testing a patch.
Subject: Bug 24642 CVSROOT: /cvsroot/classpath Module name: classpath Branch: Changes by: Casey Marshall <rsdio@savannah.gnu.org> 06/04/14 18:33:43 Modified files: . : ChangeLog NEWS java/security : SecureRandom.java Added files: vm/reference/java/security: VMSecureRandom.java Log message: 2006-04-14 Casey Marshall <csm@gnu.org> Fixes PR classpath/24642 * NEWS: add note about SecureRandom changes, and addition of VMSecureRandom. * java/security/SecureRandom.java (isSeeded): new field. (setSeed, setSeed): set `isSeeded' to `true.' (nextBytes): seed this instance if `isSeeded' is false. (getSeed): call `generateSeed.' (SECURERANDOM_SOURCE, JAVA_SECURITY_EGD, logger): new constants. (generateSeed, generateSeed): new methods. * vm/reference/java/security/VMSecureRandom.java: new file. CVSWeb URLs: http://cvs.savannah.gnu.org/viewcvs/classpath/classpath/ChangeLog.diff?tr1=1.7110&tr2=1.7111&r1=text&r2=text http://cvs.savannah.gnu.org/viewcvs/classpath/classpath/NEWS.diff?tr1=1.131&tr2=1.132&r1=text&r2=text http://cvs.savannah.gnu.org/viewcvs/classpath/classpath/java/security/SecureRandom.java.diff?tr1=1.21&tr2=1.22&r1=text&r2=text http://cvs.savannah.gnu.org/viewcvs/classpath/classpath/vm/reference/java/security/VMSecureRandom.java?rev=1.1
Fixed in CVS.