Well19937c.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.rng.core.source32;

  18. /**
  19.  * This class implements the WELL19937c pseudo-random number generator
  20.  * from François Panneton, Pierre L'Ecuyer and Makoto Matsumoto.
  21.  * <p>
  22.  * This generator is described in a paper by Fran&ccedil;ois Panneton,
  23.  * Pierre L'Ecuyer and Makoto Matsumoto
  24.  * <a href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng.pdf">
  25.  * Improved Long-Period Generators Based on Linear Recurrences Modulo 2</a>
  26.  * ACM Transactions on Mathematical Software, 32, 1 (2006).
  27.  * The errata for the paper are in
  28.  * <a href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng-errata.txt">wellrng-errata.txt</a>.
  29.  * </p>
  30.  *
  31.  * @see <a href="http://www.iro.umontreal.ca/~panneton/WELLRNG.html">WELL Random number generator</a>
  32.  * @since 1.0
  33.  */
  34. public class Well19937c extends Well19937a {
  35.     /**
  36.      * Creates a new random number generator.
  37.      *
  38.      * @param seed Initial seed.
  39.      */
  40.     public Well19937c(int[] seed) {
  41.         super(seed);
  42.     }

  43.     /** {@inheritDoc} */
  44.     @Override
  45.     public int next() {
  46.         int z4 = super.next();

  47.         // Matsumoto-Kurita tempering to get a maximally equidistributed generator.
  48.         z4 ^= (z4 << 7) & 0xe46e1700;
  49.         z4 ^= (z4 << 15) & 0x9b868000;

  50.         return z4;
  51.     }
  52. }