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

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

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

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to generate a list of N random numbers between specific range in Python

2 Answers

0 votes
import random

def GenerateRandomNumbers(_from, _to, N):
   lst = []
   for j in range(N):
      lst.append(random.randint(_from, _to))
   return lst

N = 10
lst = GenerateRandomNumbers(1, 30, N)

print(lst)


'''
run:

[18, 10, 25, 16, 30, 2, 27, 12, 19, 7]

'''

 



answered Sep 27, 2023 by avibootz
edited Sep 27, 2023 by avibootz
0 votes
import random

# random.randrange(start, stop, step) 

def GenerateRandomNumbers(_from, _to, N):
   return [random.randrange(_from, _to, 1) for i in range(N)] 

N = 10
lst = GenerateRandomNumbers(1, 30, N)

print(lst)


'''
run:

[15, 23, 24, 8, 2, 12, 27, 28, 10, 20]

'''

 



answered Sep 27, 2023 by avibootz
edited Sep 27, 2023 by avibootz
...