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.3 by jsr166, Thu Mar 19 06:50:01 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).
# Line 37 | Line 37 | public class ThreadLocalRandom extends R
37      /**
38       * The random seed. We can't use super.seed
39       */
40 <    private long rnd;
40 >    private long rnd;
41  
42      /**
43       * Initialization flag to permit the first and only allowed call
# Line 65 | Line 65 | public class ThreadLocalRandom extends R
65  
66      /**
67       * Constructor called only by localRandom.initialValue.
68 <     * We rely on the fact that the superclass no-arg constructor
68 >     * We rely on the fact that the superclass no-arg constructor
69       * invokes setSeed exactly once to initialize.
70       */
71      ThreadLocalRandom() {
# Line 83 | Line 83 | public class ThreadLocalRandom extends R
83      /**
84       * Throws UnsupportedOperationException. Setting seeds in this
85       * generator is unsupported.
86 <     * @throw UnsupportedOperationException always
86 >     * @throws UnsupportedOperationException always
87       */
88 <    public void setSeed(long seed) {
88 >    public void setSeed(long seed) {
89          if (initialized)
90              throw new UnsupportedOperationException();
91          initialized = true;
# Line 126 | Line 126 | public class ThreadLocalRandom extends R
126          // iteration (at most 31 of them but usually much less),
127          // randomly choose both whether to include high bit in result
128          // (offset) and whether to continue with the lower vs upper
129 <        // half (which makes a difference only if odd).
129 >        // half (which makes a difference only if odd).
130          long offset = 0;
131          while (n >= Integer.MAX_VALUE) {
132 <            int bits = next(2);
132 >            int bits = next(2);
133              long half = n >>> 1;
134              long nextn = ((bits & 2) == 0)? half : n - half;
135              if ((bits & 1) == 0)
# Line 183 | Line 183 | public class ThreadLocalRandom extends R
183          return nextDouble() * (bound - least) + least;
184      }
185  
186 < }
186 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines