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