Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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]
 
PREVIOUS NEXT
Tagged: #python #generate #set #random #numbers
ADD COMMENT
Topic
Name
6+8 =