def _roll_random(n):
 bits = util.bit_length((n - 1))
 byte_count = ((bits + 7) // 8)
 hbyte_mask = (pow(2, (bits % 8)) - 1)
 while True:
  x = os.urandom(byte_count)
  if (hbyte_mask > 0):
   x = (byte_mask(x[0], hbyte_mask) + x[1:])
  num = util.inflate_long(x, 1)
  if (num < n):
   break
 return num

def _roll_random ( n ) : bits = util . bit_length ( ( n - 1 ) ) byte_count = ( ( bits + 7 ) // 8 ) hbyte_mask = ( pow ( 2 , ( bits % 8 ) ) - 1 ) while True : x = os . urandom ( byte_count ) if ( hbyte_mask > 0 ) : x = ( byte_mask ( x [ 0 ] , hbyte_mask ) + x [ 1 : ] ) num = util . inflate_long ( x , 1 ) if ( num < n ) : break return num
returns a random # from 0 to n-1 .