def getRandomInteger(N, randfunc=None):
 if (randfunc is None):
  _import_Random()
  randfunc = Random.new().read
 S = randfunc((N >> 3))
 odd_bits = (N % 8)
 if (odd_bits != 0):
  char = (ord(randfunc(1)) >> (8 - odd_bits))
  S = (bchr(char) + S)
 value = bytes_to_long(S)
 return value

def getRandomInteger ( N , randfunc = None ) : if ( randfunc is None ) : _import_Random ( ) randfunc = Random . new ( ) . read S = randfunc ( ( N >> 3 ) ) odd_bits = ( N % 8 ) if ( odd_bits != 0 ) : char = ( ord ( randfunc ( 1 ) ) >> ( 8 - odd_bits ) ) S = ( bchr ( char ) + S ) value = bytes_to_long ( S ) return value
getrandominteger:long return a random number with at most n bits .