Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,563 questions

56,781 answers

573 users

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
...