/*
 * Java Genetic Algorithm Library (@__identifier__@).
 * Copyright (c) @__year__@ Franz Wilhelmstötter
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Author:
 *     Franz Wilhelmstötter (franz.wilhelmstoetter@gmx.at)
 *
 */
package org.jenetics.util;

import java.util.Random;

/**
 * This implementation is not thread-safe.
 *
 *Implementation of the highest quality recommended generator. The constructor is called with
an integer seed and creates an instance of the generator. The member functions int64, doub,
and int32 return the next values in the random sequence, as a variable type indicated by their
names. The period of the generator is
 3.138 * 10^57.

 Seite 342
 *
 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
 * @since 1.1
 * @version 1.1 &mdash; <em>$Date: 2012-11-17 $</em>
 */
public class HQ64Random extends Random {

	private static final long serialVersionUID = 1L;

	private long _u = 0L;
	private long _v = 0L;
	private long _w = 0L;


	public HQ64Random() {
		this(System.nanoTime());
	}

	public HQ64Random(final long seed) {
		init(seed);
	}

	private void init(final long seed) {
		final long s = seed == 0 ? 0xdeadbeef : seed;

		_u = s^_v;
		_v = 4101842887655102017L;
		_w  = 1L;
		nextLong();
		_v = _u;
		nextLong();
		_w = _v;
		nextLong();
	}

	@Override
	public int nextInt() {
		//final long x = nextLong();
		//return (int)(x >>> 32)^(int)(x << 32);
		return (int)(nextLong() >>> 32);
	}

	@Override
	public long nextLong() {
		_u = _u*2862933555777941757L + 7046029254386353087L;
		_v ^= _v >> 17;
		_v ^= _v << 31;
		_v ^= _v >> 8;
		_w = 0xFFFFDA61*(_w & 0xFFFFFFFF) + (_w >> 32);

		long x = _u^(_u << 21);
		x ^= x >> 35;
		x ^= x << 4;

		return (x + _v) ^ _w;
	}

	@Override
	public float nextFloat() {
		return (float)(2.32830643653869629E-10*nextInt());
	}

	@Override
	public double nextDouble() {
		return 5.42101086242752217E-20*nextLong();
	}

	@Override
	protected int next(int bits) {
		return (int)(nextLong() >>> (64 - bits));
	}

	@Override
	public void setSeed(final long seed) {
		init(seed);
	}

}

@@ -990,48 +990,15 @@
 is i
-mplementation is not thread-safe.%0A *%0A *I
+s the i
 mple
@@ -1014,16 +1014,19 @@
  of the 
+%3Ci%3E
 highest 
@@ -1058,293 +1058,483 @@
 ator
-. The constructor is called with%0Aan integer seed and creates an instance of the generator. The member functions int64, doub,%0Aand int32 return the next values in the random sequence, as a variable type indicated by their%0Anames. The period of the generator is%0A 3.138 * 10%5E57.%0A%0A Seite 342
+,%3C/i%3E%0A * suggested in%0A * %3Cp%3E%0A * %3Cstrong%3ENumerical Recipes 3rd Edition: The Art of Scientific Computing%3C/strong%3E%0A * %3Cbr/%3E%0A * %3Cem%3EChapter 7. Random Numbers; Page 342%3C/em%3E%0A * %3Cbr/%3E%0A * %3Csmall%3ECambridge University Press New York, NY, USA %C2%A92007%3C/small%3E%0A * %3Cbr/%3E%0A * ISBN:0521880688 9780521880688%0A * %3Cbr/%3E%0A * %5B%3Ca href=%22http://www.nr.com/%22%3Ehttp://www.nr.com/%3C/a%3E%5D.%0A * %3Cp/%3E%0A * The period of the generator is &asymp;3.138&sdot;10%3Csup%3E57%3C/sup%3E. This%0A * implementation is not thread-safe.
 %0A *%0A

Add scaladoc.