improved random_hex() function