commit-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[commit-cp] [bug #13270] Random number generation creates invalid values


From: anonymous
Subject: [commit-cp] [bug #13270] Random number generation creates invalid values.
Date: Thu, 2 Jun 2005 13:08:44 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.7) Gecko/20050421 Firefox/1.0.3 (Debian package 1.0.3-2)

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/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]