static public int [ ] randomIntegers ( int start , int end , int size ) { Preconditions . checkArgument ( start < end , "Start must be less than end." ) ; Random random = new Random ( ) ; random . setSeed ( System . currentTimeMillis ( ) ) ; int [ ] result = new int [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { int l = random . nextInt ( ) ; double d = ( double ) ( end - start ) / ( Integer . MAX_VALUE - Integer . MIN_VALUE ) * l + start ; if ( d <= start ) { l = start ; } else if ( d >= end ) { l = end ; } else { l = ( int ) d ; } result [ i ] = l ; } return result ; }
Generate random int values