Hello.
When I run the attached code, I often (as often as 50%) get the
following, which I've never seen before:
[treaves@double BoxMaintenance]$ java TestString
String == rkmmDBV6
String length == 8
****************
Another exception has been detected while we were handling last error.
Dumping information about last error:
ERROR REPORT FILE = (N/A)
PC = 0x0x4161903e
SIGNAL = 11
FUNCTION NAME = (N/A)
LIBRARY NAME = (N/A)
Please check ERROR REPORT FILE for further information, if there is any.
Good bye.
[treaves@double BoxMaintenance]$
I am running Sun's jdk1.3.1rc2 an a RH modified system, 2.4.4 kernel, 512
meg memory. Any ideas?
import java.security.SecureRandom;
public class TestString{
public static void main(String[] args){
SecureRandom rng = new SecureRandom();
byte[] array = new byte[1];
int index = 0;
String testString = null;
char testChar;
StringBuffer buffer = new StringBuffer();
do {
rng.nextBytes(array);
try{
testChar = new String(array, "US-ASCII").charAt(0);
} catch(Exception e){
continue;
}
if (Character.isLetterOrDigit(testChar)) {
buffer.append(testChar);
if (buffer.length() == 8) {
break;
}
}
} while ( true );
String string = buffer.toString();
System.out.println("String == " + string);
System.out.println("String length == " + string.length());
}
}