start = Decimal('0.0')
width = Decimal('1.0')
for ch in string:
    d_start, d_width = probabilities[ch]
start += Decimal(d_start) * width
width *= Decimal(d_width)
return random.uniform(float(start), float(start + width))
Python set decimal precision