// Copyright(c) 1996,1997 ObjectSpace, Inc.
// Portions Copyright(c) 1995, 1996 Hewlett-Packard Company.

import java.util.Random;

/**
 * An easy-to-use random number generator.
 * <p>
 * @version 3.1.0
 * @author ObjectSpace, Inc.
 */

public class Randomizer extends Random
{
	/**
	* Initializes the generator using a seed based on the current time.
	**/
	public Randomizer()
	{
	}

	/**
	* Initializes the generator using a specific seed; useful for generating
	* a repeatable stream of random numbers.
	* @param seed The initial seed.
	* @see java.util.Random#setSeed
	**/
	public Randomizer( long seed )
	{
		super( seed );
	}

	/**
	* Generates an int value between 1 and the given limit.
	* @param hi The upper bound.
	* @return An integer value.
	* @see java.util.Random#nextInt
	**/
	public int nextInt( int hi )
	{
		return nextInt( 1, hi );
	}

	/**
	* Generates an int value between the given limits.
	* @param lo The lower bound.
	* @param hi The upper bound.
	* @return An integer value.
	* @see java.util.Random#nextInt
	**/
	public int nextInt( int lo, int hi )
	{
		if ( lo > hi )
			throw new InvalidOperationException( "invalid range: " + lo + " > " + hi );
		return ( Math.abs( super.nextInt() ) % ( hi - lo + 1 ) ) + lo;
	}

	/**
	* Generates a long value between 1 and the given limit.
	* @param hi The upper bound.
	* @return A long value.
	* @see java.util.Random#nextLong
	**/
	public long nextLong( long hi )
	{
		return nextLong( 1, hi );
	}

	/**
	* Generates a long value between the given limits.
	* @param lo The lower bound.
	* @param hi The upper bound.
	* @return A long integer value.
	* @see java.util.Random#nextLong
	**/
	public long nextLong( long lo, long hi )
	{
		if ( lo > hi )
			throw new InvalidOperationException( "invalid range: " + lo + " > " + hi );
		return ( Math.abs( super.nextLong() ) % ( hi - lo + 1 ) ) + lo;
	}

	/**
	* Generates a float value between 1.0 and the given limit.
	* @param hi The upper bound.
	* @return A float value.
	* @see java.util.Random#nextFloat
	**/
	public float nextFloat( float hi )
	{
		return nextFloat( 1, hi );
	}

	/**
	* Generates a float value between the given limits.
	* @param lo The lower bound.
	* @param hi The upper bound.
	* @return A float value.
	* @see java.util.Random#nextFloat
	**/
	public float nextFloat( float lo, float hi )
	{
		if ( lo > hi )
			throw new InvalidOperationException( "invalid range: " + lo + " > " + hi );
		return ( Math.abs( super.nextFloat() ) % ( hi - lo + 1 ) ) + lo;
	}

	/**
	* Generates a double value between 1.0 and the given limit.
	* @param hi The upper bound.
	* @return A double value.
	* @see java.util.Random#nextDouble
	**/
	public double nextDouble( double hi )
	{
		return nextDouble( 1, hi );
	}

	/**
	* Generates a double value between the given limits.
	* @param lo The lower bound.
	* @param hi The upper bound.
	* @return A double value.
	* @see java.util.Random#nextDouble
	**/
	public double nextDouble( double lo, double hi )
	{
		if ( lo > hi )
			throw new InvalidOperationException( "invalid range: " + lo + " > " + hi );
		return ( Math.abs( super.nextDouble() ) % ( hi - lo + 1 ) ) + lo;
	}
	
	static final long serialVersionUID = 9176119848813218452L;
}
