public static long getRandomLong(Random random, long n) {
    if (n <= 0) {
      throw new IllegalArgumentException("Cannot generate random long in range [0,n) for n<=0.");
    }

    final int BITS_PER_LONG = 63;
    long bits, val;
    do {
      bits = random.nextLong() & (~(1L << BITS_PER_LONG));
      val = bits % n;
    } while (bits - val + (n - 1) < 0L);
    return val;
  }
Get a pseudo-random long uniformly between 0 and n-1. Stolen from {@link java.util.Random#nextInt()}.

@param random random object used to generate the random number so that we generate
                    uniforml random between 0 and n-1
@param n the bound
@return a value select randomly from the range {@code [0..n)}.
ambry-utils/src/main/java/com/github/ambry/utils/Utils.java