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 64-bit generator suitable for {@code double} generation. This is slightly faster than the
22   * all-purpose generator {@link XoShiRo512StarStar}.
23   *
24   * <p>This is a member of the Xor-Shift-Rotate family of generators. Memory footprint is 512 bits
25   * and the period is 2<sup>512</sup>-1. Speed is expected to be slower than
26   * {@link XoShiRo256Plus}.</p>
27   *
28   * @see <a href="http://xoshiro.di.unimi.it/xoshiro512plus.c">Original source code</a>
29   * @see <a href="http://xoshiro.di.unimi.it/">xorshiro / xoroshiro generators</a>
30   * @since 1.3
31   */
32  public class XoShiRo512Plus extends AbstractXoShiRo512 {
33      /**
34       * Creates a new instance.
35       *
36       * @param seed Initial seed.
37       * If the length is larger than 8, only the first 8 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 XoShiRo512Plus(long[] seed) {
42          super(seed);
43      }
44  
45      /**
46       * Creates a new instance using an 8 element seed.
47       * A seed containing all zeros will create a non-functional generator.
48       *
49       * @param seed0 Initial seed element 0.
50       * @param seed1 Initial seed element 1.
51       * @param seed2 Initial seed element 2.
52       * @param seed3 Initial seed element 3.
53       * @param seed4 Initial seed element 4.
54       * @param seed5 Initial seed element 5.
55       * @param seed6 Initial seed element 6.
56       * @param seed7 Initial seed element 7.
57       */
58      public XoShiRo512Plus(long seed0, long seed1, long seed2, long seed3,
59                            long seed4, long seed5, long seed6, long seed7) {
60          super(seed0, seed1, seed2, seed3, seed4, seed5, seed6, seed7);
61      }
62  
63      /**
64       * Creates a copy instance.
65       *
66       * @param source Source to copy.
67       */
68      protected XoShiRo512Plus(XoShiRo512Plus source) {
69          super(source);
70      }
71  
72      /** {@inheritDoc} */
73      @Override
74      protected long nextOutput() {
75          return state0 + state2;
76      }
77  
78      /** {@inheritDoc} */
79      @Override
80      protected XoShiRo512Plus copy() {
81          // This exists to ensure the jump function performed in the super class returns
82          // the correct class type. It should not be public.
83          return new XoShiRo512Plus(this);
84      }
85  }