1 |
|
/* |
2 |
< |
* Copyright 1995-2007 Sun Microsystems, Inc. All Rights Reserved. |
2 |
> |
* Copyright 1995-2008 Sun Microsystems, Inc. All Rights Reserved. |
3 |
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
|
* |
5 |
|
* This code is free software; you can redistribute it and/or modify it |
32 |
|
* An instance of this class is used to generate a stream of |
33 |
|
* pseudorandom numbers. The class uses a 48-bit seed, which is |
34 |
|
* modified using a linear congruential formula. (See Donald Knuth, |
35 |
< |
* <i>The Art of Computer Programming, Volume 3</i>, Section 3.2.1.) |
35 |
> |
* <i>The Art of Computer Programming, Volume 2</i>, Section 3.2.1.) |
36 |
|
* <p> |
37 |
|
* If two instances of {@code Random} are created with the same |
38 |
|
* seed, and the same sequence of method calls is made for each, they |
50 |
|
* <p> |
51 |
|
* Many applications will find the method {@link Math#random} simpler to use. |
52 |
|
* |
53 |
+ |
* <p>Instances of {@code java.util.Random} are threadsafe. |
54 |
+ |
* However, the concurrent use of the same {@code java.util.Random} |
55 |
+ |
* instance across threads may encounter contention and consequent |
56 |
+ |
* poor performance. Consider instead using |
57 |
+ |
* {@link java.util.concurrent.ThreadLocalRandom} in multithreaded |
58 |
+ |
* designs. |
59 |
+ |
* |
60 |
+ |
* <p>Instances of {@code java.util.Random} are not cryptographically |
61 |
+ |
* secure. Consider instead using {@link java.security.SecureRandom} to |
62 |
+ |
* get a cryptographically secure pseudo-random number generator for use |
63 |
+ |
* by security-sensitive applications. |
64 |
+ |
* |
65 |
|
* @author Frank Yellin |
54 |
– |
* @version %I%, %G% |
66 |
|
* @since 1.0 |
67 |
|
*/ |
68 |
|
public |
516 |
|
|
517 |
|
// The seed is read in as {@code long} for |
518 |
|
// historical reasons, but it is converted to an AtomicLong. |
519 |
< |
long seedVal = (long) fields.get("seed", -1L); |
519 |
> |
long seedVal = fields.get("seed", -1L); |
520 |
|
if (seedVal < 0) |
521 |
|
throw new java.io.StreamCorruptedException( |
522 |
|
"Random: invalid seed"); |