/*
 * 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;


/**
 * Some helper method concerning random number generation.
 *
 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
 * @since 1.1
 * @version 1.1 &mdash; <em>$Date: 2012-12-06 $</em>
 */
class random {

	private random() {
		throw new AssertionError("Don't create an 'random' instance.");
	}

	static byte[] seed(final byte[] seed) {
		for (int i = 0, len = seed.length; i < len;) {
			int n = Math.min(len - i, Long.SIZE/Byte.SIZE);

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

		return seed;
	}

	static long seed(final long seed) {
		long s = seed^nanoTimeSeed2();
		s ^= s << 21;
		s ^= s >>> 35;
		s ^= s << 4;
		return s;
	}

	/**
	 * Calculating a 64 bit seed value which can be used for initializing PRNGs.
	 *
	 * @return the random seed value.
	 */
	static long seed() {
		long seed = seed(nanoTimeSeed());
		seed ^= seed << 17;
		seed ^= seed >>> 31;
		seed ^= seed << 8;
		return seed(seed);
	}

	private static long nanoTimeSeed() {
		return
		((System.nanoTime() & 255) << 56) |
		((System.nanoTime() & 255) << 48) |
		((System.nanoTime() & 255) << 40) |
		((System.nanoTime() & 255) << 32) |
		((System.nanoTime() & 255) << 24) |
		((System.nanoTime() & 255) << 16) |
		((System.nanoTime() & 255) <<  8) |
		((System.nanoTime() & 255) <<  0);
	}
	
	private static long nanoTimeSeed2() {
		return
		((System.nanoTime() & 255) << 56) |
		((System.nanoTime() & 255) <<  0) |
		((System.nanoTime() & 255) << 32) |
		((System.nanoTime() & 255) << 16) |
		((System.nanoTime() & 255) << 24) |
		((System.nanoTime() & 255) << 40) |
		((System.nanoTime() & 255) <<  8) |
		((System.nanoTime() & 255) << 48);
	}

}




@@ -1526,142 +1526,8 @@
 %09%7D%0A%0A
-%09static long seed(final long seed) %7B%0A%09%09long s = seed%5EnanoTimeSeed2();%0A%09%09s %5E= s %3C%3C 21;%0A%09%09s %5E= s %3E%3E%3E 35;%0A%09%09s %5E= s %3C%3C 4;%0A%09%09return s;%0A%09%7D%0A%0A
 %09/**
@@ -1677,40 +1677,114 @@
 %7B%0A%09%09
-long seed = seed(nanoTime
+return seed(nanoTimeSeed());%0A%09%7D%0A%09%0A%09static long seed(final long base) %7B%0A%09%09long seed = base%5EobjectHash
 Seed()
-)
 ;%0A%09%09
@@ -1864,14 +1864,8 @@
 seed
-(seed)
 ;%0A%09%7D
@@ -1883,32 +1883,34 @@
 static long 
-nanoTime
+objectHash
 Seed() %7B%0A%09%09r
@@ -1918,317 +1918,81 @@
 turn
-%0A%09%09((System.nanoTime() & 255) %3C%3C 56) %7C%0A%09%09((System.nanoTime() & 255) %3C%3C 48) %7C%0A%09%09((System.nanoTime() & 255) %3C%3C 40) %7C%0A%09%09((System.nanoTime() & 255) %3C%3C 32) %7C%0A%09%09((System.nanoTime() & 255) %3C%3C 24) %7C%0A%09%09((System.nanoTime() & 255) %3C%3C 16) %7C%0A%09%09((System.nanoTime() & 255) %3C%3C  8) %7C%0A%09%09((System.nanoTime() & 255) %3C%3C  0
+ ((long)(new Object().hashCode()) %3C%3C 32) %7C new Object().hashCode(
 );%0A%09%7D%0A%09%0A
 %09pri
@@ -1987,16 +1987,18 @@
 );%0A%09%7D%0A%09%0A
+%09%0A
 %09private
@@ -2022,17 +2022,16 @@
 TimeSeed
-2
 () %7B%0A%09%09r
@@ -2106,18 +2106,18 @@
 255) %3C%3C 
- 0
+24
 ) %7C%0A%09%09((
@@ -2144,18 +2144,18 @@
 255) %3C%3C 
-32
+48
 ) %7C%0A%09%09((
@@ -2192,46 +2192,8 @@
 ) %7C%0A
-%09%09((System.nanoTime() & 255) %3C%3C 24) %7C%0A
 %09%09((
@@ -2296,18 +2296,56 @@
 255) %3C%3C 
-48
+32) %7C%0A%09%09((System.nanoTime() & 255) %3C%3C  0
 );%0A%09%7D%0A%0A%7D

Optimize 'random.seed' functions.