I am trying to check if a randomly generated value is inside one of several ranges I have. Those ranges go from 0 to 1, and whenever I try to use arange it doesn't find it. I tried to transform all the values to integers as well in order to use range, but it keeps missing the number.
The purpose of this snippet is to find which range the random number belongs to, in order to know to know what capacity the tank would have. For example, if the random number is 0.70, then the tank would have a capacity of 100 lt.
The simplest version I've tried is the following:
import random
import numpy as np
tank_capacity = [20,30,50,75,100]
pbb = [0.01,0.10,0.25,0.30,0.25]
pbb_acum = [0,0.10,0.35,0.65,0.90]
dict_pbb_acum = dict(zip(tank_capacity,pbb_acum))
combinations = [tank_capacity[i: i + 2] for i in range(len(tank_capacity)-1)]
n = random.random()
print(n)
if n >= 0.9:
print("found")
else:
for item in combinations:
if n in np.arange(dict_pbb_acum[item[0]], dict_pbb_acum[item[1]],0.01):
print("found")
else:
print("not found")
Thanks in advance!