final long internalNextLong ( long origin , long bound ) { long r = mix64 ( nextSeed ( ) ) ; if ( origin < bound ) { long n = bound - origin , m = n - 1 ; if ( ( n & m ) == 0L ) // power of two r = ( r & m ) + origin ; else if ( n > 0L ) { // reject over-represented candidates for ( long u = r >>> 1 ; // ensure nonnegative u + m - ( r = u % n ) < 0L ; // rejection check u = mix64 ( nextSeed ( ) ) >>> 1 ) // retry ; r += origin ; } else { // range not representable as long while ( r < origin || r >= bound ) r = mix64 ( nextSeed ( ) ) ; } } return r ; }
The form of nextLong used by LongStream Spliterators . If origin is greater than bound acts as unbounded form of nextLong else as bounded form .