def _random_range(**kwargs):
 min_inclusive = kwargs.pop('min_inclusive', None)
 max_inclusive = kwargs.pop('max_inclusive', None)
 max_exclusive = kwargs.pop('max_exclusive', None)
 randfunc = kwargs.pop('randfunc', None)
 if kwargs:
  raise ValueError(('Unknown keywords: ' + str(kwargs.keys)))
 if (None not in (max_inclusive, max_exclusive)):
  raise ValueError('max_inclusive and max_exclusive cannot be both specified')
 if (max_exclusive is not None):
  max_inclusive = (max_exclusive - 1)
 if (None in (min_inclusive, max_inclusive)):
  raise ValueError('Missing keyword to identify the interval')
 if (randfunc is None):
  randfunc = Random.new().read
 norm_maximum = (max_inclusive - min_inclusive)
 bits_needed = Integer(norm_maximum).size_in_bits()
 norm_candidate = (-1)
 while (not (0 <= norm_candidate <= norm_maximum)):
  norm_candidate = _random(max_bits=bits_needed, randfunc=randfunc)
 return (norm_candidate + min_inclusive)

def _random_range ( ** kwargs ) : min_inclusive = kwargs . pop ( 'min_inclusive' , None ) max_inclusive = kwargs . pop ( 'max_inclusive' , None ) max_exclusive = kwargs . pop ( 'max_exclusive' , None ) randfunc = kwargs . pop ( 'randfunc' , None ) if kwargs : raise ValueError ( ( 'Unknown keywords: ' + str ( kwargs . keys ) ) ) if ( None not in ( max_inclusive , max_exclusive ) ) : raise ValueError ( 'max_inclusive and max_exclusive cannot be both specified' ) if ( max_exclusive is not None ) : max_inclusive = ( max_exclusive - 1 ) if ( None in ( min_inclusive , max_inclusive ) ) : raise ValueError ( 'Missing keyword to identify the interval' ) if ( randfunc is None ) : randfunc = Random . new ( ) . read norm_maximum = ( max_inclusive - min_inclusive ) bits_needed = Integer ( norm_maximum ) . size_in_bits ( ) norm_candidate = ( - 1 ) while ( not ( 0 <= norm_candidate <= norm_maximum ) ) : norm_candidate = _random ( max_bits = bits_needed , randfunc = randfunc ) return ( norm_candidate + min_inclusive )
generate a random integer within a given internal .