URL: <http://savannah.gnu.org/bugs/?func=detailitem&item_id=13270>
Summary: Random number generation creates invalid values. Project: classpath Submitted by: None Submitted on: Thu 06/02/2005 at 13:08 Category: classpath Severity: 3 - Normal Status: None Privacy: Public Assigned to: None Open/Closed: Open Platform Version: None _______________________________________________________ Details: While trying to run Azureus on latest SableVM snapshot( 2005-05-14, using classpath 0.15 ) I came across a StringOutOfBoundsException and managed to track the error to the Random number generation, it creates numbers higher/lower than what it's supposed to( 2147483647 and -2147483647 ) Here's a piece of code that causes this problem, the code inside the main has been taken from Azureus source code and modified with the System.out so you can see the output: public class Test { public static void main( String args[] ) { String uniqueId =""; String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; for(int i = 0 ; i < 20 ; i++) { int pos = (int) ( Math.random() * chars.length()); System.out.println( pos ); uniqueId += chars.charAt(pos); } } } Running this piece of code with classpath 0.13 generates the correct output, random numbers less than chars.length() _______________________________________________________ Reply to this item at: <http://savannah.gnu.org/bugs/?func=detailitem&item_id=13270> _______________________________________________ Message sent via/by Savannah http://savannah.gnu.org/ _______________________________________________ Commit-classpath mailing list Commit-classpath@gnu.org http://lists.gnu.org/mailman/listinfo/commit-classpath