/*******************************************************************************
 * In this class, I am including the functionality of both:
 *     The Random    class, and
 *     The RandomUse class
 *******************************************************************************/
class Random
{
    int    minimum;                         //instance fields
    int    maximum;                 
    double randGenerated;                       
    int    rand;                        


    Random(int min, int max)                //constructor that takes min, max       
    {
        minimum = min;
        maximum = max;

        compute();                                              //call compute method
    }

    void compute()                           //method to generate the random number                          
    {
        randGenerated = Math.random();

        rand = (int) (randGenerated * (maximum-minimum+1) );    //random distribution over max-min
        rand = rand + minimum;                                  //add the minimum value
    }

    int getRand()                           //getter method to return the random number generated                         
    {
        return(rand);
    }

    public String toString()                //method that returns everything        
    {
        String s = "Random number from: "  +  minimum  + " to: " + maximum + "\n" + 
                   "raw: " + randGenerated + " is--> " + rand;            
        return(s);
    }
}


/*******************************************************************************
 * A class with main to test/use the Random class
 *******************************************************************************/
public class RandomUse 
{
    public static void main (String[ ] args)
    {               
        Random obj = new Random(0,5);           //create the random obj
        int num   = obj.getRand();              //generate the random num
        System.out.println(num);                //print the number

        Random obj2 = new Random(1,6);          //in 2 steps
        System.out.println(obj2.getRand());

        Random obj3;                            //create a var of type Random

        obj3 = new Random(11,16);               //use it
        System.out.println(obj3.getRand());

        obj3 = new Random(10,20);               //re-use the same obj3 object
        System.out.println(obj3.getRand());

        System.out.println( (new Random(-100,100)).getRand() );   //all in 1 step  


        obj3.minimum = -1000;                           //or, I can set the instance 
        obj3.maximum =  1000;                           //minimum and maximum values                        
        obj3.compute();                                 //and call the compute method directly
        System.out.println(obj3.getRand());


        System.out.println(obj.toString());
        System.out.println(obj2.toString());
        System.out.println(obj3);                       //no need to add .toString()
    }
}