001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.rng.core.source32;
018
019/**
020 * This class implements the WELL19937c pseudo-random number generator
021 * from François Panneton, Pierre L'Ecuyer and Makoto Matsumoto.
022 * <p>
023 * This generator is described in a paper by Fran&ccedil;ois Panneton,
024 * Pierre L'Ecuyer and Makoto Matsumoto
025 * <a href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng.pdf">
026 * Improved Long-Period Generators Based on Linear Recurrences Modulo 2</a>
027 * ACM Transactions on Mathematical Software, 32, 1 (2006).
028 * The errata for the paper are in
029 * <a href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng-errata.txt">wellrng-errata.txt</a>.
030 * </p>
031 *
032 * @see <a href="http://www.iro.umontreal.ca/~panneton/WELLRNG.html">WELL Random number generator</a>
033 * @since 1.0
034 */
035public class Well19937c extends Well19937a {
036    /**
037     * Creates a new random number generator.
038     *
039     * @param seed Initial seed.
040     */
041    public Well19937c(int[] seed) {
042        super(seed);
043    }
044
045    /** {@inheritDoc} */
046    @Override
047    public int next() {
048        int z4 = super.next();
049
050        // Matsumoto-Kurita tempering to get a maximally equidistributed generator.
051        z4 ^= (z4 << 7) & 0xe46e1700;
052        z4 ^= (z4 << 15) & 0x9b868000;
053
054        return z4;
055    }
056}