code: public static long nextLong(final long n, final Random random) {
  		if (n <= 0) {
  			throw new IllegalArgumentException(format(
  				"n is smaller than one: %d", n
  			));
  		}
  
  		long bits;
  		long result;
  		do {
  			bits = random.nextLong() & 0x7fffffffffffffffL;
  			result = bits%n;
  		} while (bits - result + (n - 1) < 0);
  
  		return result;
  	}
docs: Returns a pseudo-random, uniformly distributed int value between 0
  (inclusive) and the specified value (exclusive), drawn from the given
  random number generator's sequence.
  
  @param n the bound on the random number to be returned. Must be
  positive.
  @param random the random engine used for creating the random number.
  @return the next pseudo-random, uniformly distributed int value
  between 0 (inclusive) and n (exclusive) from the given random
  number generator's sequence
  @throws IllegalArgumentException if n is smaller than 1.
  @throws NullPointerException if the given {@code random}
  engine is {@code null}.