How to generate a random list of N tuples of size M between min and max in Python

1 Answer

0 votes
import random

def generate_n_random_tuples(total_tuples, tuple_size, min_, max_):
   return [tuple(random.randint(min_, max_) for _ in range(tuple_size)) for _ in range(total_tuples)]

total_tuples = 5
tuple_size = 3
min_value = 0
max_value = 100

the_tuples = generate_n_random_tuples(total_tuples, tuple_size, min_value, max_value)

print(the_tuples)


   
'''
run:
   
[(3, 32, 49), (36, 91, 9), (65, 26, 4), (86, 11, 43), (8, 60, 16)]
   
'''

 



answered Jan 23 by avibootz
...