Inspect Hardware register fields attributes to generate mask value

Hi
the problem i have is the following … i have a 64-bit register that has fields that can be RO (read only) or WR(Write) . I would like to write a python script that will inspect the register fields and generate a test value based on the register writable fields - Any help ?
thank you

Args:
register (RegisterValue): Register object that will be verified to get a random value that fits
current_value (int): Current value of the register, if not is sended, the function will
try to read the value of the register
check_register_attributes (bool): Flag that will mark if the attributes of the fields from the register
need to be checked
Returns:
test_value (int):
‘’’

Get register size

reg_size = get_register_size(register)
max_value = 0xFFFF

Change the max possible value depending on the size of the register

if reg_size == 32:
max_value = MAX_POSSIBLE_VALUE_32_BITS
elif reg_size == 64:
max_value = MAX_POSSIBLE_VALUE_64_BITS

Trying to read the value of the register if non was sended

Getting a random value

test_value = random.randint(1, max_value)
#print(“Random number between 1 and 10 is % s” % (test_value))

Checking that the test value gotten is different to the current ’

if check_register_attributes:
test_value = change_value_based_on_attribute(register, test_value)
while test_value == 0x0:
test_value = random.randint(1, max_value)
# Checking that the test value gotten is different to the current ’
if check_register_attributes:
test_value = change_value_based_on_attribute(register, test_value)
return test_value