Random number wrapper class I made this class to handle any min max integer value and return a random number in the entered parameter range. I tested it to work with all combinations(I think). But is this totally wrong or written with unnecessary amounts of code? Are there obvious Java convention violations or obvious redundancy in this?

I was wondering if it was possible to do the same without instantiating Random, since I have read that object instantiation is more resource demanding than method invoking, like invoking Math.random(). I just couldn't make that work, unfortunately, as I didn't save the strange non-working code that that ended with.

I tried the solution here. However, I don't understand what the rand() part is, which is too bad since it seemed really simple with just one line of code.

abstract class RandomInteger {
     static int randomNumber;

     public static int returnRandomIntRange(int start, int end){

         if(end &lt; start){
             throw new IllegalArgumentException("Start cannot exceed End.");
         } else if(end == 0 &amp;&amp; start == 0){
             throw new IllegalArgumentException("Start and End can't both be 0.");
         } else if(end == start){
             throw new IllegalArgumentException("Start and End can't be the same.");

         } else if(end &gt;= 0 &amp;&amp; start &lt;= 0){
             Random random=new Random();
             int range;                      
             range = end - start + 1;            
             System.out.println("aEnd &gt; 0 &amp;&amp; aStart &lt; 0. 1range is: " + range);
             randomNumber=(random.nextInt(range))+(start);
             System.out.println("aEnd &gt; 0 &amp;&amp; aStart &gt;= 0. invoked. 1randomNumber is: " + randomNumber);

         } else if(end &gt; 0 &amp;&amp; start &gt; 0){
             Random randomGenerator=new Random();
             int range;         
             range = end - start + 1;
             System.out.println("aEnd &gt; 0 &amp;&amp; aStart &gt;= 0. invoked. 2range is: " + range);
             randomNumber = randomGenerator.nextInt(range) + start;
             System.out.println("aEnd &gt; 0 &amp;&amp; aStart &gt;= 0. invoked. 2randomNumber is: " + randomNumber);

         } else if(end &lt; 0 &amp;&amp; start &lt; 0){
             Random randomGenerator=new Random();
             int range;
             range = (start - end -1) * -1;                         
             System.out.println("aEnd &lt;= 0 &amp;&amp; aStart &lt; 0. invoked. 3range is: " + range);
             randomNumber = ((randomGenerator.nextInt(range)+ start));
             System.out.println("aEnd &lt;= 0 &amp;&amp; aStart &lt; 0. invoked. 3randomNumber is: " + randomNumber);
         }

         return randomNumber;
     }

}
That does look a little confusing.  The example you looked at is for C, not Java.  I would do this:

int random = (int) Math.floor(Math.random() * (max - min + 1) ) + min;


It works like this:  Math.random() returns a double between 0 and 1 (although never actually equal to 1).  The full range of values you want is (max - min + 1) (the +1 is because you probably want max to min inclusive), so this will scale the number over the correct number of integer values.  We floor it (round down) because we want an int, and finally shift it upwards by adding min to put the numbers in the correct range.  We also cast to an int since we don't want it as a double.

EDIT: On further inspection, this is better; no casting and rounding of doubles:

Random rand = new Random();
int random = rand.nextInt(max - min + 1) + min;