Friday, November 26, 2010

Random number generator

 private static int RandomNumberGenerator(int aStart, int aEnd, Random aRandom){  
      if ( aStart > aEnd ) {  
       throw new IllegalArgumentException("Start cannot exceed End.");  
      }  
      long range = (long)aEnd - (long)aStart + 1;  
      long fraction = (long)(range * aRandom.nextDouble());  
      int randomNumber = (int)(fraction + aStart);    
      return randomNumber;  
 }  

No comments: