private static int asInteger ( final long [ ] data , final int n ) { int t ; int cnt = 0 ; long seed = 0 ; if ( n < 2 ) { throw new SketchesArgumentException ( "Given value of n must be &gt; 1." ) ; } if ( n > ( 1 << 30 ) ) { while ( ++ cnt < 10000 ) { final long [ ] h = MurmurHash3 . hash ( data , seed ) ; t = ( int ) ( h [ 0 ] & INT_MASK ) ; if ( t < n ) { return t ; } t = ( int ) ( ( h [ 0 ] >>> 33 ) ) ; if ( t < n ) { return t ; } t = ( int ) ( h [ 1 ] & INT_MASK ) ; if ( t < n ) { return t ; } t = ( int ) ( ( h [ 1 ] >>> 33 ) ) ; if ( t < n ) { return t ; } seed += PRIME ; } // end while throw new SketchesStateException ( "Internal Error: Failed to find integer &lt; n within 10000 iterations." ) ; } final long mask = ceilingPowerOf2 ( n ) - 1 ; while ( ++ cnt < 10000 ) { final long [ ] h = MurmurHash3 . hash ( data , seed ) ; t = ( int ) ( h [ 0 ] & mask ) ; if ( t < n ) { return t ; } t = ( int ) ( ( h [ 0 ] >>> 33 ) & mask ) ; if ( t < n ) { return t ; } t = ( int ) ( h [ 1 ] & mask ) ; if ( t < n ) { return t ; } t = ( int ) ( ( h [ 1 ] >>> 33 ) & mask ) ; if ( t < n ) { return t ; } seed += PRIME ; } // end while throw new SketchesStateException ( "Internal Error: Failed to find integer &lt; n within 10000 iterations." ) ; }
Returns a deterministic uniform random integer with a minimum inclusive value of zero and a maximum exclusive value of n given the input data .