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 */
017
018package org.apache.commons.rng.core.source32;
019
020/**
021 * A fast all-purpose 32-bit generator. For faster generation of {@code float} values try the
022 * {@link XoShiRo128Plus} generator.
023 *
024 * <p>This is a member of the Xor-Shift-Rotate family of generators. Memory footprint is 128
025 * bits.</p>
026 *
027 * @see <a href="http://xoshiro.di.unimi.it/xoshiro128starstar.c">Original source code</a>
028 * @see <a href="http://xoshiro.di.unimi.it/">xorshiro / xoroshiro generators</a>
029 * @since 1.3
030 */
031public class XoShiRo128StarStar extends AbstractXoShiRo128 {
032    /**
033     * Creates a new instance.
034     *
035     * @param seed Initial seed.
036     * If the length is larger than 4, only the first 4 elements will
037     * be used; if smaller, the remaining elements will be automatically
038     * set. A seed containing all zeros will create a non-functional generator.
039     */
040    public XoShiRo128StarStar(int[] seed) {
041        super(seed);
042    }
043
044    /**
045     * Creates a new instance using a 4 element seed.
046     * A seed containing all zeros will create a non-functional generator.
047     *
048     * @param seed0 Initial seed element 0.
049     * @param seed1 Initial seed element 1.
050     * @param seed2 Initial seed element 2.
051     * @param seed3 Initial seed element 3.
052     */
053    public XoShiRo128StarStar(int seed0, int seed1, int seed2, int seed3) {
054        super(seed0, seed1, seed2, seed3);
055    }
056
057    /**
058     * Creates a copy instance.
059     *
060     * @param source Source to copy.
061     */
062    protected XoShiRo128StarStar(XoShiRo128StarStar source) {
063        super(source);
064    }
065
066    /** {@inheritDoc} */
067    @Override
068    protected int nextOutput() {
069        return Integer.rotateLeft(state0 * 5, 7) * 9;
070    }
071
072    /** {@inheritDoc} */
073    @Override
074    protected XoShiRo128StarStar copy() {
075        // This exists to ensure the jump function performed in the super class returns
076        // the correct class type. It should not be public.
077        return new XoShiRo128StarStar(this);
078    }
079}