XoRoShiRo64StarStar.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.source32;

  18. /**
  19.  * A fast all-purpose 32-bit generator. For faster generation of {@code float} values try the
  20.  * {@link XoRoShiRo64Star} generator.
  21.  *
  22.  * <p>This is a member of the Xor-Shift-Rotate family of generators. Memory footprint is 64
  23.  * bits.</p>
  24.  *
  25.  * @see <a href="http://xoshiro.di.unimi.it/xoroshiro64starstar.c">Original source code</a>
  26.  * @see <a href="http://xoshiro.di.unimi.it/">xorshiro / xoroshiro generators</a>
  27.  * @since 1.3
  28.  */
  29. public class XoRoShiRo64StarStar extends AbstractXoRoShiRo64 {
  30.     /**
  31.      * Creates a new instance.
  32.      *
  33.      * @param seed Initial seed.
  34.      * If the length is larger than 2, only the first 2 elements will
  35.      * be used; if smaller, the remaining elements will be automatically
  36.      * set. A seed containing all zeros will create a non-functional generator.
  37.      */
  38.     public XoRoShiRo64StarStar(int[] seed) {
  39.         super(seed);
  40.     }

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

  51.     /** {@inheritDoc} */
  52.     @Override
  53.     protected int nextOutput() {
  54.         return Integer.rotateLeft(state0 * 0x9e3779bb, 5) * 5;
  55.     }
  56. }