def random_int ( maximum_value ) : if maximum_value == 0 : return 0 elif maximum_value == 1 : return random_bits ( 1 ) bits = math . floor ( math . log2 ( maximum_value ) ) result = random_bits ( bits ) + random_int ( maximum_value - ( ( 2 ** bits ) - 1 ) ) return result
how to test for maximum of a random integer function python
Random generator ( PyCrypto getrandbits wrapper ) . The result is a non - negative value .
def random_int(maximum_value):
	""" Random generator (PyCrypto getrandbits wrapper). The result is a non-negative value.

	:param maximum_value: maximum integer value
	:return: int
	"""
	if maximum_value == 0:
		return 0
	elif maximum_value == 1:
		return random_bits(1)

	bits = math.floor(math.log2(maximum_value))
	result = random_bits(bits) + random_int(maximum_value - ((2 ** bits) - 1))
	return result