Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python generate set of random numbers

# Loop method
import random
# Empty set for reusability
randomlist = []
# Loop 5 times generating nums 
for i in range(0,5): # 0-4 non-inclusive
	n = random.randint(-10,10) # -10-10 inclusive
	randomlist.append(n)
print(randomlist)
# [7, -4, 8, 6, -5]

# random.sample() method
randomlist2 = []
#Generate 5 random numbers between 10 and 30
randomlist = random.sample(range(10, 30), 5)
print(randomlist2)
# [16, 19, 13, 18, 15]
Comment

python generate set of random numbers

# Loop method
import random
# Empty set for reusability
randomlist = []
# Loop 5 times generating nums 
for i in range(0,5): # 0-4 non-inclusive
	n = random.randint(-10,10) # -10-10 inclusive
	randomlist.append(n)
print(randomlist)
# [7, -4, 8, 6, -5]

# random.sample() method
randomlist2 = []
#Generate 5 random numbers between 10 and 30
randomlist = random.sample(range(10, 30), 5)
print(randomlist2)
# [16, 19, 13, 18, 15]
Comment

PREVIOUS NEXT
Code Example
Python :: chatbot using python github 
Python :: variable in regex python 
Python :: while loop odd numbers python 
Python :: even numbers in python 
Python :: activate venv 
Python :: disable gpu in jupyter notebook in tensorflow 
Python :: decrypt vnc password 
Python :: what is += python 
Python :: tkinter background image python 3 
Python :: timedelta python days 
Python :: compare times python 
Python :: how to check if a variable in python is a specific data type 
Python :: break while loop python 
Python :: image.open no such file or directory 
Python :: df.fillna(-999,inplace=True) 
Python :: python spliting string into list 
Python :: python swarm plot seaborn 
Python :: odoo order by xml rpc 
Python :: load static 
Python :: form action in django 
Python :: random.uniform python 
Python :: time in regression expression python 
Python :: python replace with something else 
Python :: pytest logcli to write to file 
Python :: how to filter a series in pandas 
Python :: how to set a single main title above all the subplots with pyplot 
Python :: how to set numerecal index in pandas 
Python :: python enum to int 
Python :: url_for 
Python :: matplotlib draw line x1, y1 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =