How would you prevent the errors when calling function biased_random defined below and what are the limits for arguments scale and bias to hold for preventing problems with big or small numbers?
def biased_random(scale, bias):
return random.random() ** bias * scale
>>> sum(biased_random(1000, 10) for x in range(100)) / 100
64.94178302276364
>>> sum(biased_random(1000, 100000) for x in range(100)) / 100
0.0
>>> sum(biased_random(1000, 0.002) for x in range(100)) / 100
998.0704866851909
I’d use
sys.maxintto figure out what the overflow point is. Then divide or nth-root it and compare with the number that you have:Hope this helps