View Javadoc
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  
18  package org.apache.commons.rng.core.source64;
19  
20  /**
21   * A fast RNG implementing the {@code XorShift1024*} algorithm.
22   *
23   * <p>Note: This supersedes {@link XorShift1024Star}. The sequences emitted by both
24   * generators are correlated.</p>
25   *
26   * <p>This generator differs only in the final multiplier (a fixed-point representation
27   * of the golden ratio), which eliminates linear dependencies from one of the lowest
28   * bits.</p>
29   *
30   * @see <a href="http://xorshift.di.unimi.it/xorshift1024star.c">Original source code</a>
31   * @see <a href="https://en.wikipedia.org/wiki/Xorshift">Xorshift (Wikipedia)</a>
32   * @since 1.3
33   */
34  public class XorShift1024StarPhi extends XorShift1024Star {
35      /**
36       * Creates a new instance.
37       *
38       * @param seed Initial seed.
39       * If the length is larger than 16, only the first 16 elements will
40       * be used; if smaller, the remaining elements will be automatically
41       * set. A seed containing all zeros will create a non-functional generator.
42       */
43      public XorShift1024StarPhi(long[] seed) {
44          super(seed, 0x9e3779b97f4a7c13L);
45      }
46  
47      /**
48       * Creates a copy instance.
49       *
50       * @param source Source to copy.
51       */
52      protected XorShift1024StarPhi(XorShift1024StarPhi source) {
53          super(source);
54      }
55  
56      /** {@inheritDoc} */
57      @Override
58      protected XorShift1024StarPhi copy() {
59          // This exists to ensure the jump function performed in the super class returns
60          // the correct class type. It should not be public.
61          return new XorShift1024StarPhi(this);
62      }
63  }