def getRandomNumber(N, randfunc):
 S = randfunc((N / 8))
 odd_bits = (N % 8)
 if (odd_bits != 0):
  char = (ord(randfunc(1)) >> (8 - odd_bits))
  S = (chr(char) + S)
 value = bytes_to_long(S)
 value |= (2L ** (N - 1))
 assert (size(value) >= N)
 return value

def getRandomNumber ( N , randfunc ) : S = randfunc ( ( N / 8 ) ) odd_bits = ( N % 8 ) if ( odd_bits != 0 ) : char = ( ord ( randfunc ( 1 ) ) >> ( 8 - odd_bits ) ) S = ( chr ( char ) + S ) value = bytes_to_long ( S ) value |= ( 2 L ** ( N - 1 ) ) assert ( size ( value ) >= N ) return value
getrandomnumber:long return an n-bit random number .