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.13 by jsr166, Wed Aug 19 17:52:50 2009 UTC vs.
Revision 1.17 by jsr166, Fri Jul 19 19:34:43 2013 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7   package jsr166y;
# Line 34 | Line 34 | import java.util.Random;
34   */
35   public class ThreadLocalRandom extends Random {
36      // same constants as Random, but must be redeclared because private
37 <    private final static long multiplier = 0x5DEECE66DL;
38 <    private final static long addend = 0xBL;
39 <    private final static long mask = (1L << 48) - 1;
37 >    private static final long multiplier = 0x5DEECE66DL;
38 >    private static final long addend = 0xBL;
39 >    private static final long mask = (1L << 48) - 1;
40  
41      /**
42       * The random seed. We can't use super.seed.
# Line 44 | Line 44 | public class ThreadLocalRandom extends R
44      private long rnd;
45  
46      /**
47 <     * Initialization flag to permit the first and only allowed call
48 <     * to setSeed (inside Random constructor) to succeed.  We can't
49 <     * allow others since it would cause setting seed in one part of a
50 <     * program to unintentionally impact other usages by the thread.
47 >     * Initialization flag to permit calls to setSeed to succeed only
48 >     * while executing the Random constructor.  We can't allow others
49 >     * since it would cause setting seed in one part of a program to
50 >     * unintentionally impact other usages by the thread.
51       */
52      boolean initialized;
53  
# Line 69 | Line 69 | public class ThreadLocalRandom extends R
69  
70      /**
71       * Constructor called only by localRandom.initialValue.
72     * We rely on the fact that the superclass no-arg constructor
73     * invokes setSeed exactly once to initialize.
72       */
73      ThreadLocalRandom() {
74          super();
75 +        initialized = true;
76      }
77  
78      /**
# Line 94 | Line 93 | public class ThreadLocalRandom extends R
93      public void setSeed(long seed) {
94          if (initialized)
95              throw new UnsupportedOperationException();
97        initialized = true;
96          rnd = (seed ^ multiplier) & mask;
97      }
98  
# Line 109 | Line 107 | public class ThreadLocalRandom extends R
107       *
108       * @param least the least value returned
109       * @param bound the upper bound (exclusive)
110 +     * @return the next value
111       * @throws IllegalArgumentException if least greater than or equal
112       * to bound
114     * @return the next value
113       */
114      public int nextInt(int least, int bound) {
115          if (least >= bound)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines