Python code to generate private ECDSA key Would this Python code generate a valid ECDSA private key?

import random

def r(a, b):
    sys_ran = random.SystemRandom()
    return sys_ran.randint(a, b)

def create_private_key():
    hex_chars = '0123456789ABCDEF'
    ran_hex = '';

    for i in range(64):
        ran_hex += hex_chars[r(0, 15)]

    max_hex = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141'

    if int(ran_hex, 16) &lt;= int(max_hex, 16):
        return ran_hex
    else:
        return create_private_key()

private_key = create_private_key()
print('Private key: ' + private_key)


As far as I can tell from the Bitcoin wiki, an ECDSA private key is any 64 character hexadecimal (or the corresponding decimal) number between 0x1 and 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141. It doesn't mention anything about any special algorithms required for the private key to be valid.
Yes, it will generate a random ECDSA private key in hexadecimal ASCII form. You don't really need to specifically check whether the key is greater than the maximum -- pretty much every implementation that will take an ECDSA key in hexadecimal ASCII knows how to handle a key above the maximum sanely. (By subtracting the max value from the key and then using that.)