XorShift1024StarPhi.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 RNG implementing the {@code XorShift1024*} algorithm.
  20.  *
  21.  * <p>Note: This supersedes {@link XorShift1024Star}. The sequences emitted by both
  22.  * generators are correlated.</p>
  23.  *
  24.  * <p>This generator differs only in the final multiplier (a fixed-point representation
  25.  * of the golden ratio), which eliminates linear dependencies from one of the lowest
  26.  * bits.</p>
  27.  *
  28.  * @see <a href="http://xorshift.di.unimi.it/xorshift1024star.c">Original source code</a>
  29.  * @see <a href="https://en.wikipedia.org/wiki/Xorshift">Xorshift (Wikipedia)</a>
  30.  * @since 1.3
  31.  */
  32. public class XorShift1024StarPhi extends XorShift1024Star {
  33.     /**
  34.      * Creates a new instance.
  35.      *
  36.      * @param seed Initial seed.
  37.      * If the length is larger than 16, only the first 16 elements will
  38.      * be used; if smaller, the remaining elements will be automatically
  39.      * set. A seed containing all zeros will create a non-functional generator.
  40.      */
  41.     public XorShift1024StarPhi(long[] seed) {
  42.         super(seed, 0x9e3779b97f4a7c13L);
  43.     }

  44.     /**
  45.      * Creates a copy instance.
  46.      *
  47.      * @param source Source to copy.
  48.      */
  49.     protected XorShift1024StarPhi(XorShift1024StarPhi source) {
  50.         super(source);
  51.     }

  52.     /** {@inheritDoc} */
  53.     @Override
  54.     protected XorShift1024StarPhi copy() {
  55.         // This exists to ensure the jump function performed in the super class returns
  56.         // the correct class type. It should not be public.
  57.         return new XorShift1024StarPhi(this);
  58.     }
  59. }