001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.rng.core.source32;
018
019/**
020 * A Permuted Congruential Generator (PCG) that is composed of a 64-bit Multiplicative Congruential
021 * Generator (MCG) combined with the XSH-RS (xorshift; random shift) output
022 * transformation to create 32-bit output.
023 *
024 * <p>State size is 64 bits and the period is 2<sup>62</sup>.</p>
025 *
026 * @see <a href="http://www.pcg-random.org/">
027 *  PCG, A Family of Better Random Number Generators</a>
028 * @since 1.3
029 */
030public class PcgMcgXshRs32 extends AbstractPcgMcg6432 {
031    /**
032     * Creates a new instance.
033     *
034     * @param seed Initial seed.
035     */
036    public PcgMcgXshRs32(Long seed) {
037        super(seed);
038    }
039
040    /** {@inheritDoc} */
041    @Override
042    protected int transform(long x) {
043        final int count = (int)(x >>> 61);
044        return (int)((x ^ (x >>> 22)) >>> (22 + count));
045    }
046}