I need to choose a random float number in two ranges in python:
0. < n < 0.2 or 0.8 < n < 1.
Right now I only have one range:
random.uniform(0, 0.2)
The full line (I'm mapping warm color hsv values):
couleur = hsv2rgb(random.uniform(0, 0.2), 1, 1))
If someone could help... !
You can do a weighted selection between the intervals:
from numpy import random
def uniform_two(a1, a2, b1, b2):
# Calc weight for each range
delta_a = a2 - a1
delta_b = b2 - b1
if random.rand() < delta_a / (delta_a + delta_b):
return random.uniform(a1, a2)
else:
return random.uniform(b1, b2)
print uniform_two(0, 0.2, 0.8, 1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With