public static int consistentHash(long input, int buckets) {
    """
	Assigns to {@code input} a "bucket" in the range {@code [0, buckets)}, in a uniform manner that
	minimizes the need for remapping as {@code buckets} grows. That is, {@code consistentHash(h,
	n)} equals:
	
	<ul>
	<li>{@code n - 1}, with approximate probability {@code 1/n}
	<li>{@code consistentHash(h, n - 1)}, otherwise (probability {@code 1 - 1/n})
	</ul>
	
	<p>This method is suitable for the common use case of dividing work among buckets that meet the
	following conditions:
	
	<ul>
	<li>You want to assign the same fraction of inputs to each bucket.
	<li>When you reduce the number of buckets, you can accept that the most recently added
	buckets will be removed first. More concretely, if you are dividing traffic among tasks,
	you can decrease the number of tasks from 15 and 10, killing off the final 5 tasks, and
	{@code consistentHash} will handle it. If, however, you are dividing traffic among
	servers {@code alpha}, {@code bravo}, and {@code charlie} and you occasionally need to
	take each of the servers offline, {@code consistentHash} will be a poor fit: It provides
	no way for you to specify which of the three buckets is disappearing. Thus, if your
	buckets change from {@code [alpha, bravo, charlie]} to {@code [bravo, charlie]}, it will
	assign all the old {@code alpha} traffic to {@code bravo} and all the old {@code bravo}
	traffic to {@code charlie}, rather than letting {@code bravo} keep its traffic.
	</ul>
	
	
	<p>See the <a href="http://en.wikipedia.org/wiki/Consistent_hashing">Wikipedia article on
	consistent hashing</a> for more information.
    """
    checkArgument(buckets > 0, "buckets must be positive: %s", buckets);
    LinearCongruentialGenerator generator = new LinearCongruentialGenerator(input);
    int candidate = 0;
    int next;

    // Jump from bucket to bucket until we go out of range
    while (true) {
      next = (int) ((candidate + 1) / generator.nextDouble());
      if (next >= 0 && next < buckets) {
        candidate = next;
      } else {
        return candidate;
      }
    }
  }
public static int consistentHash(long input, int buckets) {
    checkArgument(buckets > 0, "buckets must be positive: %s", buckets);
    LinearCongruentialGenerator generator = new LinearCongruentialGenerator(input);
    int candidate = 0;
    int next;

    // Jump from bucket to bucket until we go out of range
    while (true) {
      next = (int) ((candidate + 1) / generator.nextDouble());
      if (next >= 0 && next < buckets) {
        candidate = next;
      } else {
        return candidate;
      }
    }
  }
public static int consistentHash ( long input , int buckets ) { checkArgument ( buckets > 0 , "buckets must be positive: %s" , buckets ) ; LinearCongruentialGenerator generator = new LinearCongruentialGenerator ( input ) ; int candidate = 0 ; int next ; // Jump from bucket to bucket until we go out of range while ( true ) { next = ( int ) ( ( candidate + 1 ) / generator . nextDouble ( ) ) ; if ( next >= 0 && next < buckets ) { candidate = next ; } else { return candidate ; } } }
Assigns to {@code input} a "bucket" in the range {@code [0, buckets)}, in a uniform manner that
minimizes the need for remapping as {@code buckets} grows. That is, {@code consistentHash(h,
n)} equals:

<ul>
<li>{@code n - 1}, with approximate probability {@code 1/n}
<li>{@code consistentHash(h, n - 1)}, otherwise (probability {@code 1 - 1/n})
</ul>

<p>This method is suitable for the common use case of dividing work among buckets that meet the
following conditions:

<ul>
<li>You want to assign the same fraction of inputs to each bucket.
<li>When you reduce the number of buckets, you can accept that the most recently added
buckets will be removed first. More concretely, if you are dividing traffic among tasks,
you can decrease the number of tasks from 15 and 10, killing off the final 5 tasks, and
{@code consistentHash} will handle it. If, however, you are dividing traffic among
servers {@code alpha}, {@code bravo}, and {@code charlie} and you occasionally need to
take each of the servers offline, {@code consistentHash} will be a poor fit: It provides
no way for you to specify which of the three buckets is disappearing. Thus, if your
buckets change from {@code [alpha, bravo, charlie]} to {@code [bravo, charlie]}, it will
assign all the old {@code alpha} traffic to {@code bravo} and all the old {@code bravo}
traffic to {@code charlie}, rather than letting {@code bravo} keep its traffic.
</ul>


<p>See the <a href="http://en.wikipedia.org/wiki/Consistent_hashing">Wikipedia article on
consistent hashing</a> for more information.
Assigns to { @code input } a bucket in the range { @code [ 0 buckets ) } in a uniform manner that minimizes the need for remapping as { @code buckets } grows . That is { @code consistentHash ( h n ) } equals :