XoRoShiRo128Plus.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.source64;

  18. /**
  19.  * A fast 64-bit generator suitable for {@code double} generation. This is slightly faster than the
  20.  * all-purpose generator {@link XoRoShiRo128StarStar}.
  21.  *
  22.  * <p>This is a member of the Xor-Shift-Rotate family of generators. Memory footprint is 128 bits
  23.  * and the period is 2<sup>128</sup>-1. Speed is expected to be similar to
  24.  * {@link XoShiRo256Plus}.</p>
  25.  *
  26.  * @see <a href="http://xoshiro.di.unimi.it/xoroshiro128plus.c">Original source code</a>
  27.  * @see <a href="http://xoshiro.di.unimi.it/">xorshiro / xoroshiro generators</a>
  28.  * @since 1.3
  29.  */
  30. public class XoRoShiRo128Plus extends AbstractXoRoShiRo128 {
  31.     /**
  32.      * Creates a new instance.
  33.      *
  34.      * @param seed Initial seed.
  35.      * If the length is larger than 2, only the first 2 elements will
  36.      * be used; if smaller, the remaining elements will be automatically
  37.      * set. A seed containing all zeros will create a non-functional generator.
  38.      */
  39.     public XoRoShiRo128Plus(long[] seed) {
  40.         super(seed);
  41.     }

  42.     /**
  43.      * Creates a new instance using a 2 element seed.
  44.      * A seed containing all zeros will create a non-functional generator.
  45.      *
  46.      * @param seed0 Initial seed element 0.
  47.      * @param seed1 Initial seed element 1.
  48.      */
  49.     public XoRoShiRo128Plus(long seed0, long seed1) {
  50.         super(seed0, seed1);
  51.     }

  52.     /**
  53.      * Creates a copy instance.
  54.      *
  55.      * @param source Source to copy.
  56.      */
  57.     protected XoRoShiRo128Plus(XoRoShiRo128Plus source) {
  58.         super(source);
  59.     }

  60.     /** {@inheritDoc} */
  61.     @Override
  62.     protected long nextOutput() {
  63.         return state0 + state1;
  64.     }

  65.     /** {@inheritDoc} */
  66.     @Override
  67.     protected XoRoShiRo128Plus copy() {
  68.         // This exists to ensure the jump function performed in the super class returns
  69.         // the correct class type. It should not be public.
  70.         return new XoRoShiRo128Plus(this);
  71.     }
  72. }