#NEWLINE# def test_randbelow_logic( self , _log = log , int = int ) : #NEWLINE# #INDENT# for i in range ( 1 , 1000 ) : #NEWLINE# #INDENT# n = ( 1 << i ) #NEWLINE# numbits = ( i + 1 ) #NEWLINE# k = int ( ( 1.00001 + _log ( n , 2 ) ) ) #NEWLINE# self . assertEqual ( k , numbits ) #NEWLINE# self . assertEqual ( n , ( 2 ** ( k - 1 ) ) ) #NEWLINE# n += ( n - 1 ) #NEWLINE# k = int ( ( 1.00001 + _log ( n , 2 ) ) ) #NEWLINE# self . assertIn ( k , [ k , ( numbits + 1 ) ] ) #NEWLINE# self . assertTrue ( ( ( 2 ** k ) > n > ( 2 ** ( k - 2 ) ) ) ) #NEWLINE# n -= ( n >> 15 ) #NEWLINE# k = int ( ( 1.00001 + _log ( n , 2 ) ) ) #NEWLINE# self . assertEqual ( k , numbits ) #NEWLINE# self . assertTrue ( ( ( 2 ** k ) > n > ( 2 ** ( k - 1 ) ) ) )