// Path: prngine/src/main/java/io/jenetics/prngine/Bytes.java
// static int readInt(final byte[] bytes, final int index) {
// 	final int offset = index*Integer.BYTES;
// 	if (offset + Integer.BYTES > bytes.length) {
// 		throw new IndexOutOfBoundsException(format(
// 			"Not enough data to read int value (index=%d, bytes=%d).",
// 			index, bytes.length
// 		));
// 	}
// 
// 	return
// 		((bytes[offset    ] & 255) << 24) +
// 		((bytes[offset + 1] & 255) << 16) +
// 		((bytes[offset + 2] & 255) << 8) +
// 		((bytes[offset + 3] & 255));
// }
// 
// Path: prngine/src/main/java/io/jenetics/prngine/Bytes.java
// static long readLong(final byte[] bytes, final int index) {
// 	final int offset = index*Long.BYTES;
// 	if (offset + Long.BYTES > bytes.length) {
// 		throw new IndexOutOfBoundsException(format(
// 			"Not enough data to read long value (index=%d, bytes=%d).",
// 			index, bytes.length
// 		));
// 	}
// 
// 	return
// 		((long)(bytes[offset    ] & 255) << 56) +
// 		((long)(bytes[offset + 1] & 255) << 48) +
// 		((long)(bytes[offset + 2] & 255) << 40) +
// 		((long)(bytes[offset + 3] & 255) << 32) +
// 		((long)(bytes[offset + 4] & 255) << 24) +
// 		((bytes[offset + 5] & 255) << 16) +
// 		((bytes[offset + 6] & 255) <<  8) +
// 		(bytes[offset + 7] & 255);
// }


import java.util.random.RandomGenerator;
import static java.lang.String.format;
import static io.jenetics.prngine.Bytes.readInt;
import static io.jenetics.prngine.Bytes.readLong;
/*
 * PRNGine - Java PRNG Library (@__identifier__@).
 * Copyright (c) @__year__@ Franz Wilhelmstötter
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author:
 *    Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com)
 */
package io.jenetics.prngine;



/**
 * Implementation of an simple PRNG as proposed in
 * <a href="http://www0.cs.ucl.ac.uk/staff/d.jones/GoodPracticeRNG.pdf">
 * Good Practice in (Pseudo) Random Number Generation for Bioinformatics
 * Applications</a> (JKISS64, page 10) by <em><a href="mailto:d.jones@cs.ucl.ac.uk">
 * David Jones</a>, UCL Bioinformatics Group</em>.
 *
 * <p>
 * The following listing shows the actual PRNG implementation.
 * <pre>{@code
 * private long x, y = <seed>
 * private int z1, c1, z2, c2 = <seed>
 *
 * long nextLong() {
 *     x = 0x14ADA13ED78492ADL*x + 123456789;
 *
 *     y ^= y << 21;
 *     y ^= y >>> 17;
 *     y ^= y << 30;
 *
 *     long t = 4294584393L*_z1 + _c1;
 *     c1 = (int)(t >> 32);
 *     z1 = (int)t;
 *
 *     t = 4246477509L*z2 + c2;
 *     c2 = (int)(t >> 32);
 *     z2 = (int)t;
 *
 *     return x + y + z1 + ((long)z2 << 32);
 * }
 * }</pre>
 *
 * <p>
 * The period of this <i>PRNG</i> is &asymp; 2<sup>250</sup>
 * &asymp; 1.8&sdot;10<sup>75</sup>
 *
 * <p>
 * <strong>Not that the base implementation of the {@code KISS64Random}
 * class is not thread-safe.</strong> If multiple threads requests random
 * numbers from this class, it <i>must</i> be synchronized externally.
 *
 * @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
 * @since 1.0
 * @version 2.0.0
 */
public class KISS64Random implements SplittableRandom {

	/**
	 * The internal state of this PRNG.
	 */
	private static final class State {
		static final int SEED_BYTES = 32;

		long x, y;
		int z1, c1, z2, c2;

		State(final byte[] seed) {
			if (seed.length < SEED_BYTES) {
				throw new IllegalArgumentException(format(
					"Required %d seed bytes, but got %d.",
					SEED_BYTES, seed.length
				));
			}

			x = readLong(seed, 0);
			y = readLong(seed, 1);
// Path: prngine/src/main/java/io/jenetics/prngine/Bytes.java
// static int readInt(final byte[] bytes, final int index) {
// 	final int offset = index*Integer.BYTES;
// 	if (offset + Integer.BYTES > bytes.length) {
// 		throw new IndexOutOfBoundsException(format(
// 			"Not enough data to read int value (index=%d, bytes=%d).",
// 			index, bytes.length
// 		));
// 	}
// 
// 	return
// 		((bytes[offset    ] & 255) << 24) +
// 		((bytes[offset + 1] & 255) << 16) +
// 		((bytes[offset + 2] & 255) << 8) +
// 		((bytes[offset + 3] & 255));
// }
// 
// Path: prngine/src/main/java/io/jenetics/prngine/Bytes.java
// static long readLong(final byte[] bytes, final int index) {
// 	final int offset = index*Long.BYTES;
// 	if (offset + Long.BYTES > bytes.length) {
// 		throw new IndexOutOfBoundsException(format(
// 			"Not enough data to read long value (index=%d, bytes=%d).",
// 			index, bytes.length
// 		));
// 	}
// 
// 	return
// 		((long)(bytes[offset    ] & 255) << 56) +
// 		((long)(bytes[offset + 1] & 255) << 48) +
// 		((long)(bytes[offset + 2] & 255) << 40) +
// 		((long)(bytes[offset + 3] & 255) << 32) +
// 		((long)(bytes[offset + 4] & 255) << 24) +
// 		((bytes[offset + 5] & 255) << 16) +
// 		((bytes[offset + 6] & 255) <<  8) +
// 		(bytes[offset + 7] & 255);
// }


// Path: prngine/src/main/java/io/jenetics/prngine/KISS64Random.java
import java.util.random.RandomGenerator;
import static java.lang.String.format;
import static io.jenetics.prngine.Bytes.readInt;
import static io.jenetics.prngine.Bytes.readLong;

/*
 * PRNGine - Java PRNG Library (@__identifier__@).
 * Copyright (c) @__year__@ Franz Wilhelmstötter
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author:
 *    Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com)
 */
package io.jenetics.prngine;



/**
 * Implementation of an simple PRNG as proposed in
 * <a href="http://www0.cs.ucl.ac.uk/staff/d.jones/GoodPracticeRNG.pdf">
 * Good Practice in (Pseudo) Random Number Generation for Bioinformatics
 * Applications</a> (JKISS64, page 10) by <em><a href="mailto:d.jones@cs.ucl.ac.uk">
 * David Jones</a>, UCL Bioinformatics Group</em>.
 *
 * <p>
 * The following listing shows the actual PRNG implementation.
 * <pre>{@code
 * private long x, y = <seed>
 * private int z1, c1, z2, c2 = <seed>
 *
 * long nextLong() {
 *     x = 0x14ADA13ED78492ADL*x + 123456789;
 *
 *     y ^= y << 21;
 *     y ^= y >>> 17;
 *     y ^= y << 30;
 *
 *     long t = 4294584393L*_z1 + _c1;
 *     c1 = (int)(t >> 32);
 *     z1 = (int)t;
 *
 *     t = 4246477509L*z2 + c2;
 *     c2 = (int)(t >> 32);
 *     z2 = (int)t;
 *
 *     return x + y + z1 + ((long)z2 << 32);
 * }
 * }</pre>
 *
 * <p>
 * The period of this <i>PRNG</i> is &asymp; 2<sup>250</sup>
 * &asymp; 1.8&sdot;10<sup>75</sup>
 *
 * <p>
 * <strong>Not that the base implementation of the {@code KISS64Random}
 * class is not thread-safe.</strong> If multiple threads requests random
 * numbers from this class, it <i>must</i> be synchronized externally.
 *
 * @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
 * @since 1.0
 * @version 2.0.0
 */
public class KISS64Random implements SplittableRandom {

	/**
	 * The internal state of this PRNG.
	 */
	private static final class State {
		static final int SEED_BYTES = 32;

		long x, y;
		int z1, c1, z2, c2;

		State(final byte[] seed) {
			if (seed.length < SEED_BYTES) {
				throw new IllegalArgumentException(format(
					"Required %d seed bytes, but got %d.",
					SEED_BYTES, seed.length
				));
			}

			x = readLong(seed, 0);
			y = readLong(seed, 1);
			z1 = readInt(seed, 4);