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.source32;
19
20 /**
21 * A fast all-purpose 32-bit generator. For faster generation of {@code float} values try the
22 * {@link XoShiRo128Plus} generator.
23 *
24 * <p>This is a member of the Xor-Shift-Rotate family of generators. Memory footprint is 128
25 * bits.</p>
26 *
27 * @see <a href="http://xoshiro.di.unimi.it/xoshiro128starstar.c">Original source code</a>
28 * @see <a href="http://xoshiro.di.unimi.it/">xorshiro / xoroshiro generators</a>
29 * @since 1.3
30 */
31 public class XoShiRo128StarStar extends AbstractXoShiRo128 {
32 /**
33 * Creates a new instance.
34 *
35 * @param seed Initial seed.
36 * If the length is larger than 4, only the first 4 elements will
37 * be used; if smaller, the remaining elements will be automatically
38 * set. A seed containing all zeros will create a non-functional generator.
39 */
40 public XoShiRo128StarStar(int[] seed) {
41 super(seed);
42 }
43
44 /**
45 * Creates a new instance using a 4 element seed.
46 * A seed containing all zeros will create a non-functional generator.
47 *
48 * @param seed0 Initial seed element 0.
49 * @param seed1 Initial seed element 1.
50 * @param seed2 Initial seed element 2.
51 * @param seed3 Initial seed element 3.
52 */
53 public XoShiRo128StarStar(int seed0, int seed1, int seed2, int seed3) {
54 super(seed0, seed1, seed2, seed3);
55 }
56
57 /**
58 * Creates a copy instance.
59 *
60 * @param source Source to copy.
61 */
62 protected XoShiRo128StarStar(XoShiRo128StarStar source) {
63 super(source);
64 }
65
66 /** {@inheritDoc} */
67 @Override
68 protected int nextOutput() {
69 return Integer.rotateLeft(state0 * 5, 7) * 9;
70 }
71
72 /** {@inheritDoc} */
73 @Override
74 protected XoShiRo128StarStar copy() {
75 // This exists to ensure the jump function performed in the super class returns
76 // the correct class type. It should not be public.
77 return new XoShiRo128StarStar(this);
78 }
79 }