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