I want to get a random number between (65, 90) and (97, 122) range. I can select random number in range using
import random
random.randint(65,95)
but ˋrandint` take the only integer so how can I do?? any idea
Thanks in advance
I want to get a random number between (65, 90) and (97, 122) range. I can select random number in range using
import random
random.randint(65,95)
but ˋrandint` take the only integer so how can I do?? any idea
Thanks in advance
Alternatively:
def random():
arr1 = np.random.randint(65,90)
arr2 = np.random.randint(97,122)
out = np.stack((arr1,arr2))
out = np.random.choice(out)
return out
def random_of_ranges(*ranges):
all_ranges = sum(ranges, [])
return random.choice(all_ranges)
print(random_of_ranges(range(65, 90), range(97, 122)))
This is a very general way of handling this. You can pass any number of ranges (or subset of them). But it is rather costly, especially for very large sets (like range(1, 100000000)
). For your usecase (and maybe several others in the vicinity) it would be sufficient, though.
Make your own?
import random
def my_rand():
numbers = list()
numbers.append(random.randint(65,95))
numbers.append(random.randint(97,122))
return numbers[random.randint(0,1)]