ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166y/ThreadLocalRandom.java
(Generate patch)

Comparing jsr166/src/jsr166y/ThreadLocalRandom.java (file contents):
Revision 1.2 by dl, Mon Jan 12 20:46:29 2009 UTC vs.
Revision 1.6 by jsr166, Wed Jul 22 01:36:51 2009 UTC

# Line 18 | Line 18 | import java.util.*;
18   * contention.  ThreadLocalRandoms are particularly appropriate when
19   * multiple tasks (for example, each a {@link ForkJoinTask}), use
20   * random numbers in parallel in thread pools.
21 < *
21 > *
22   * <p>Usages of this class should typically be of the form:
23 < * <code>ThreadLocalRandom.current().nextX(...)</code> (where
24 < * <code>X</code> is <code>Int</code>, <code>Long</code>, etc).
23 > * {@code ThreadLocalRandom.current().nextX(...)} (where
24 > * {@code X} is {@code Int}, {@code Long}, etc).
25   * When all usages are of this form, it is never possible to
26   * accidently share ThreadLocalRandoms across multiple threads.
27   *
28   * <p>This class also provides additional commonly used bounded random
29   * generation methods.
30 + *
31 + * @since 1.7
32 + * @author Doug Lea
33   */
34   public class ThreadLocalRandom extends Random {
35      // same constants as Random, but must be redeclared because private
# Line 37 | Line 40 | public class ThreadLocalRandom extends R
40      /**
41       * The random seed. We can't use super.seed
42       */
43 <    private long rnd;
43 >    private long rnd;
44  
45      /**
46       * Initialization flag to permit the first and only allowed call
# Line 65 | Line 68 | public class ThreadLocalRandom extends R
68  
69      /**
70       * Constructor called only by localRandom.initialValue.
71 <     * We rely on the fact that the superclass no-arg constructor
71 >     * We rely on the fact that the superclass no-arg constructor
72       * invokes setSeed exactly once to initialize.
73       */
74      ThreadLocalRandom() {
# Line 73 | Line 76 | public class ThreadLocalRandom extends R
76      }
77  
78      /**
79 <     * Returns the current Thread's ThreadLocalRandom
79 >     * Returns the current Thread's ThreadLocalRandom.
80       * @return the current Thread's ThreadLocalRandom
81       */
82      public static ThreadLocalRandom current() {
# Line 83 | Line 86 | public class ThreadLocalRandom extends R
86      /**
87       * Throws UnsupportedOperationException. Setting seeds in this
88       * generator is unsupported.
89 <     * @throw UnsupportedOperationException always
89 >     * @throws UnsupportedOperationException always
90       */
91 <    public void setSeed(long seed) {
91 >    public void setSeed(long seed) {
92          if (initialized)
93              throw new UnsupportedOperationException();
94          initialized = true;
# Line 126 | Line 129 | public class ThreadLocalRandom extends R
129          // iteration (at most 31 of them but usually much less),
130          // randomly choose both whether to include high bit in result
131          // (offset) and whether to continue with the lower vs upper
132 <        // half (which makes a difference only if odd).
132 >        // half (which makes a difference only if odd).
133          long offset = 0;
134          while (n >= Integer.MAX_VALUE) {
135 <            int bits = next(2);
135 >            int bits = next(2);
136              long half = n >>> 1;
137              long nextn = ((bits & 2) == 0)? half : n - half;
138              if ((bits & 1) == 0)
# Line 183 | Line 186 | public class ThreadLocalRandom extends R
186          return nextDouble() * (bound - least) + least;
187      }
188  
189 < }
189 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines