/*
 * Java Genetic Algorithm 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@gmx.at)
 */
package org.jenetics.util;

import static java.lang.Math.min;

import java.util.Random;

import org.jenetics.internal.math.random;

/**
 * An abstract base class which eases the implementation of {@code Random}
 * objects which natively creates random {@code long} values. All other
 * {@code Random} functions are optimized using this {@code long} values.
 *
 * [code]
 * public class MyRandom64 extends Random64 {
 *     \@Override
 *     public long nextLong() {
 *         // Only this method must be implemented.
 *         ...
 *     }
 * }
 * [/code]
 *
 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
 * @since 1.1
 * @version 2.0 &mdash; <em>$Date: 2014-05-11 $</em>
 */
public abstract class Random64 extends PRNG {

	private static final long serialVersionUID = 1L;

	protected Random64(final long seed) {
		super(seed);
	}

	protected Random64() {
		this(math.random.seed());
	}

	/**
	 * Force to explicitly override the Random.nextLong() method. All other
	 * methods of this class are implemented by calling this method.
	 */
	@Override
	public abstract long nextLong();


	@Override
	public boolean nextBoolean() {
		return (nextLong() & 0x8000000000000000L) != 0L;
	}

	@Override
	public int nextInt() {
		return (int)(nextLong() >>> Integer.SIZE);
	}

	@Override
	protected int next(final int bits) {
		return (int)(nextLong() >>> (Long.SIZE - bits));
	}

	/**
	 * Optimized version of the {@link Random#nextBytes(byte[])} method for
	 * 64-bit random engines.
	 */
	@Override
	public void nextBytes(final byte[] bytes) {
		for (int i = 0, len = bytes.length; i < len;) {
			int n = min(len - i, Long.BYTES);

			for (long x = nextLong(); --n >= 0; x >>= Byte.SIZE) {
				bytes[i++] = (byte)x;
			}
		}
	}

	@Override
	public float nextFloat() {
		return random.toFloat2(nextLong());
	}

	/**
	 * Optimized version of the {@link Random#nextDouble()} method for 64-bit
	 * random engines.
	 */
	@Override
	public double nextDouble() {
		return random.toDouble2(nextLong());
	}

}

@@ -814,22 +814,88 @@
 va.util.
-Random
+Objects;%0Aimport java.util.Random;%0Aimport java.util.function.LongSupplier
 ;%0A%0Aimpor
@@ -1502,12 +1502,12 @@
 14-0
-5-11
+7-03
  $%3C/
@@ -2782,24 +2782,24 @@
 tDouble() %7B%0A
-
 %09%09return ran
@@ -2829,10 +2829,782 @@
 ));%0A%09%7D%0A%0A
+%0A%09/**%0A%09 * Create a new %7B@code Random64%7D instance, where the random numbers are%0A%09 * generated by the given long %7B@code supplier%7D.%0A%09 *%0A%09 * @param supplier the random number supplier%0A%09 * @return a new %7B@code Random64%7D instance%0A%09 * @throws java.lang.NullPointerException if the given %7B@code supplier%7D is%0A%09 *         %7B@code null%7D.%0A%09 */%0A%09public static Random64 of(final LongSupplier supplier) %7B%0A%09%09Objects.requireNonNull(supplier);%0A%0A%09%09return new Random64() %7B%0A%09%09%09private static final long serialVersionUID = 1L;%0A%0A%09%09%09@Override%0A%09%09%09public long nextLong() %7B%0A%09%09%09%09return supplier.getAsLong();%0A%09%09%09%7D%0A%0A%09%09%09@Override%0A%09%09%09public void setSeed(final long seed) %7B%0A%09%09%09%09throw new UnsupportedOperationException(%0A%09%09%09%09%09%22The 'setSeed(long)' method is not supported this instance.%22%0A%09%09%09%09);%0A%09%09%09%7D%0A%09%09%7D;%0A%09%7D%0A%0A
 %7D%0A

Add 'Random64.of(LongSupplier)' factory method.