18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 * or visit www.oracle.com if you need additional information or have any
20 * questions.
21 */
22
23 /*
24 * This file is available under and governed by the GNU General Public
25 * License version 2 only, as published by the Free Software Foundation.
26 * However, the following notice accompanied the original version of this
27 * file:
28 *
29 * Written by Doug Lea with assistance from members of JCP JSR-166
30 * Expert Group and released to the public domain, as explained at
31 * http://creativecommons.org/publicdomain/zero/1.0/
32 */
33
34 /*
35 * @test
36 * @bug 4949279 6937857
37 * @summary Independent instantiations of Random() have distinct seeds.
38 */
39
40 import java.util.ArrayList;
41 import java.util.HashSet;
42 import java.util.List;
43 import java.util.Random;
44
45 public class DistinctSeeds {
46 public static void main(String[] args) throws Exception {
47 // Strictly speaking, it is possible for these to randomly fail,
48 // but the probability should be small (approximately 2**-48).
49 if (new Random().nextLong() == new Random().nextLong() ||
50 new Random().nextLong() == new Random().nextLong())
51 throw new RuntimeException("Random() seeds not unique.");
52
53 // Now try generating seeds concurrently
54 class RandomCollector implements Runnable {
55 long[] randoms = new long[1<<17];
56 public void run() {
57 for (int i = 0; i < randoms.length; i++)
|
18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 * or visit www.oracle.com if you need additional information or have any
20 * questions.
21 */
22
23 /*
24 * This file is available under and governed by the GNU General Public
25 * License version 2 only, as published by the Free Software Foundation.
26 * However, the following notice accompanied the original version of this
27 * file:
28 *
29 * Written by Doug Lea with assistance from members of JCP JSR-166
30 * Expert Group and released to the public domain, as explained at
31 * http://creativecommons.org/publicdomain/zero/1.0/
32 */
33
34 /*
35 * @test
36 * @bug 4949279 6937857
37 * @summary Independent instantiations of Random() have distinct seeds.
38 * @key randomness
39 */
40
41 import java.util.ArrayList;
42 import java.util.HashSet;
43 import java.util.List;
44 import java.util.Random;
45
46 public class DistinctSeeds {
47 public static void main(String[] args) throws Exception {
48 // Strictly speaking, it is possible for these to randomly fail,
49 // but the probability should be small (approximately 2**-48).
50 if (new Random().nextLong() == new Random().nextLong() ||
51 new Random().nextLong() == new Random().nextLong())
52 throw new RuntimeException("Random() seeds not unique.");
53
54 // Now try generating seeds concurrently
55 class RandomCollector implements Runnable {
56 long[] randoms = new long[1<<17];
57 public void run() {
58 for (int i = 0; i < randoms.length; i++)
|