A random hex generator This is a program that generates a random hex value.  

# How this works:
#   uses random to get a random number
#   checks what hash method to use
#   uses that method to hash the random number
#   returns the value

import hashlib
import random as rand


def hexrandom(minint, maxint, shamode="sha1"):
    x = str(rand.randint(int(minint), int(maxint)))
    reval = None
    if shamode == "sha1":
        reval = hashlib.sha1(x.encode()).hexdigest()
    elif shamode == "sha224":
        reval = hashlib.sha224(x.encode()).hexdigest()
    elif shamode == "sha256":
        reval = hashlib.sha256(x.encode()).hexdigest()
    elif shamode == "sha384":
        reval = hashlib.sha384(x.encode()).hexdigest()
    elif shamode == "sha512":
        reval = hashlib.sha512(x.encode()).hexdigest()

    return reval


How it works is simple.
It creates a random number.
It then hashes that number.
Then, it .hexdigest()s that.
And then returns that.  

By the way, I tried being descriptive with explaining it, but it kept saying that there was unformated code. Sorry about that. The big description will be in a .md file on the repository. MarkDown file here

Development of the module this will be here.
Anytime you have a stacked if with basically all of the same comparisions, you should consider another method.
Use a dict:
The most common way to do this sort of thing is a dict.  The dict makes it easy to map a string to a method like:
sha_methods = dict(
    sha1=hashlib.sha1,
    sha224=hashlib.sha224,
    sha256=hashlib.sha256,
    sha384=hashlib.sha384,
    sha512=hashlib.sha512,
)

def hexrandom(minint, maxint, shamode=&quot;sha1&quot;):
    if shamode not in sha_mthods:
        raise ValueError(&quot;Unknown hashlib method {}&quot;.format(shamode))
    x = str(rand.randint(int(minint), int(maxint)))
    return sha_methods[shamode](x.encode()).hexdigest()

Use a direct method lookup:
In this case, since the shamode string matches the method name hashlib, we can use getattr to directly lookup this method like:
def hexrandom(minint, maxint, shamode=&quot;sha1&quot;):
    method = getattr(hashlib, shamode, None)
    if method is None:
        raise ValueError(&quot;Unknown hashlib method {}&quot;.format(shamode))
    x = str(rand.randint(int(minint), int(maxint)))
    return method(x.encode()).hexdigest()