harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r564535 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/Random.java test/api/common/tests/api/java/util/RandomTest.java
Date Fri, 10 Aug 2007 10:14:06 GMT
Author: leoli
Date: Fri Aug 10 03:14:05 2007
New Revision: 564535

URL: http://svn.apache.org/viewvc?view=rev&rev=564535
Log:
Apply patch for HARMONY-4616 ([classlib][luni]the seed of java.util.Random is not radmon enough
itself).

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Random.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/RandomTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Random.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Random.java?view=diff&rev=564535&r1=564534&r2=564535
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Random.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Random.java Fri Aug
10 03:14:05 2007
@@ -59,7 +59,7 @@
      * @see #setSeed
      */
     public Random() {
-        setSeed(System.currentTimeMillis());
+        setSeed(System.currentTimeMillis() + hashCode());
     }
 
     /**

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/RandomTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/RandomTest.java?view=diff&rev=564535&r1=564534&r2=564535
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/RandomTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/RandomTest.java
Fri Aug 10 03:14:05 2007
@@ -243,6 +243,17 @@
 					"Reseting a random to its old seed did not result in the same chain of values as it
gave before",
 					aRandom.nextLong() == randomArray[counter]);
 	}
+    
+    // two random create at a time should also generated different results
+    // regression test for Harmony 4616
+    public void test_random_generate() throws Exception {
+        for (int i = 0; i < 100; i++) {
+            Random random1 = new Random();
+            Random random2 = new Random();
+            assertFalse(random1.nextLong() == random2.nextLong());    
+        }
+    }
+
 
 	/**
 	 * Sets up the fixture, for example, open a network connection. This method



Mime
View raw message