_random: added ValueError to handled exceptions (fixes #8662)