Hi,

I had write a script in perl to randamize hex value and get the results as attached.
Which is decimal value-----hexadecimal value.

If i want to get randomized hexadecimal value 0x12c8xxxx but not 0x12c80000, what can i do? (where xxxx is not zero but with some hex value)

I search nothing on internet. Help me please if you know the solution or has any suggestion.

Thanks,
Kimberling

I suggest this

from random import randrange

def randhex(hexdigits):
    s = hex(randrange(16 ** hexdigits))
    if s[-1] == 'L':
        s = s[:-1]
    return s

for i in range(10):
    print(randhex(8))

""" my output -->
0xae662345
0xd2b915f5
0x244435bd
0xdf1c08e
0x73d6018f
0xf4b05b97
0x589e2a82
0xad3a2ea9
0xea758570
0xbe48582d

why not just

from random import randint
s = hex(randint(0x12c80000, 0x12c8ffff))
if s[-1] == "L":
    s = s[:-1]
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.