src/java.base/share/classes/java/util/Random.java

Print this page
rev 12972 : 8140606: Update library code to use internal Unsafe
Reviewed-by: duke


  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.util;
  27 import java.io.*;
  28 import java.util.concurrent.atomic.AtomicLong;
  29 import java.util.function.DoubleConsumer;
  30 import java.util.function.IntConsumer;
  31 import java.util.function.LongConsumer;
  32 import java.util.stream.DoubleStream;
  33 import java.util.stream.IntStream;
  34 import java.util.stream.LongStream;
  35 import java.util.stream.StreamSupport;
  36 
  37 import sun.misc.Unsafe;
  38 
  39 /**
  40  * An instance of this class is used to generate a stream of
  41  * pseudorandom numbers. The class uses a 48-bit seed, which is
  42  * modified using a linear congruential formula. (See Donald Knuth,
  43  * <i>The Art of Computer Programming, Volume 2</i>, Section 3.2.1.)
  44  * <p>
  45  * If two instances of {@code Random} are created with the same
  46  * seed, and the same sequence of method calls is made for each, they
  47  * will generate and return identical sequences of numbers. In order to
  48  * guarantee this property, particular algorithms are specified for the
  49  * class {@code Random}. Java implementations must use all the algorithms
  50  * shown here for the class {@code Random}, for the sake of absolute
  51  * portability of Java code. However, subclasses of class {@code Random}
  52  * are permitted to use other algorithms, so long as they adhere to the
  53  * general contracts for all the methods.
  54  * <p>
  55  * The algorithms implemented by class {@code Random} use a
  56  * {@code protected} utility method that on each invocation can supply
  57  * up to 32 pseudorandomly generated bits.




  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.util;
  27 import java.io.*;
  28 import java.util.concurrent.atomic.AtomicLong;
  29 import java.util.function.DoubleConsumer;
  30 import java.util.function.IntConsumer;
  31 import java.util.function.LongConsumer;
  32 import java.util.stream.DoubleStream;
  33 import java.util.stream.IntStream;
  34 import java.util.stream.LongStream;
  35 import java.util.stream.StreamSupport;
  36 
  37 import jdk.internal.misc.Unsafe;
  38 
  39 /**
  40  * An instance of this class is used to generate a stream of
  41  * pseudorandom numbers. The class uses a 48-bit seed, which is
  42  * modified using a linear congruential formula. (See Donald Knuth,
  43  * <i>The Art of Computer Programming, Volume 2</i>, Section 3.2.1.)
  44  * <p>
  45  * If two instances of {@code Random} are created with the same
  46  * seed, and the same sequence of method calls is made for each, they
  47  * will generate and return identical sequences of numbers. In order to
  48  * guarantee this property, particular algorithms are specified for the
  49  * class {@code Random}. Java implementations must use all the algorithms
  50  * shown here for the class {@code Random}, for the sake of absolute
  51  * portability of Java code. However, subclasses of class {@code Random}
  52  * are permitted to use other algorithms, so long as they adhere to the
  53  * general contracts for all the methods.
  54  * <p>
  55  * The algorithms implemented by class {@code Random} use a
  56  * {@code protected} utility method that on each invocation can supply
  57  * up to 32 pseudorandomly generated bits.