public long nextLong ( final long n ) { if ( n <= 0 ) throw new IllegalArgumentException ( "n must be > 0" ) ; long bits , val ; do { bits = ( nextLong ( ) >>> 1 ) ; val = bits % n ; } while ( bits - val + ( n - 1 ) < 0 ) ; return val ; }
This method is for completness sake . Returns a long drawn uniformly from 0 to n - 1 . Suffice it to say n must be > 0 or an IllegalArgumentException is raised .