#NEWLINE# def weakrandom_uniform( self , n ) : #NEWLINE# #INDENT# assert ( 0 < n ) #NEWLINE# nbits = n . bit_length ( ) #NEWLINE# nwords = ( ( nbits + 31 ) / 32 ) #NEWLINE# l = ( ( ( 1 << nbits ) - n ) % n ) #NEWLINE# while True : #NEWLINE# #INDENT# r = 0 #NEWLINE# for i in range ( nwords ) : #NEWLINE# #INDENT# r <<= 32 #NEWLINE# r |= self . weakrandom32 ( ) #NEWLINE# #UNINDENT# if ( r < l ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# return ( r % n )