package src.tools;

import java.util.Random;

public class RandomNumberGenerator {

	private static Random random;
	private static long randomSeed;

	static {
		randomSeed = System.currentTimeMillis();
		random = new Random(randomSeed);
	}

	/**
	 * This method returns a evenly distributed integer value. The boundaries
	 * are included.
	 * 
	 * @param lo
	 *            Lower bound.
	 * @param hi
	 *            Upper bound.
	 * @return Random integer from[lo,hi]
	 */
	public static int randomInt(int lo, int hi) {
		return (Math.abs(random.nextInt()) % ((hi - lo) + 1)) + lo;
	}

	/**
	 * This method returns 0 or 1 with same probability
	 * 
	 * @return Random bit
	 */
	public static int randomBit() {
		return randomInt(0, 1);
	}

	/**
	 * This method returns <code>true</code> or <code>false</code> with same
	 * probability
	 * 
	 * @return Random boolean value
	 */
	public static boolean randomBoolean() {
		return (randomBit() == 1);
	}
}
