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,900 questions

51,831 answers

573 users

How to generate N different random numbers between 1 and 100 in Python

2 Answers

0 votes
import numpy as np

N = 25

lst = np.random.choice(np.arange(1, 101), size=N, replace=False)

print(lst)


  
'''
run:
   
[ 56  40  62  63  99  50  28  84  67  10  76  79 100  55  92  48   9  39
   5  11  21  57  22  43  36]

'''

 



answered Jun 27, 2020 by avibootz
edited Jun 27, 2020 by avibootz
0 votes
import random

N = 40

lst = random.sample(range(1, 100), N)

print(lst)



  
'''
run:
   
[13, 61, 24, 67, 93, 31, 72, 55, 28, 96, 43, 84, 63, 68, 66, 60, 23, 73, 83, 86, 38, 94, 
7, 3, 82, 26, 2, 25, 11, 35, 88, 34, 36, 18, 64, 71, 1, 57, 42, 53]

'''

 



answered Jun 27, 2020 by avibootz
...