1import random
2names=['Mark', 'Sam', 'Henry']
3
4#Set any array
5random_array_item=random.choice(names)
6
7#Declare a variable as a random choice
8print(random_array_item)
9
10#Print the random choice
11#Or, if you want to arrange them in any order:
12for j in range(names):
13 print(random.choice(names))
1# To create a list of random integer values:
2import random
3randomlist = random.sample(range(10, 30), 5)
4# Output:
5# [16, 19, 13, 18, 15]
6
7# To create a list of random float numbers:
8import numpy
9random_float_array = numpy.random.uniform(75.5, 125.5, 2)
10# Output:
11# [107.50697835, 123.84889979]
1import random
2
3list = ["Item 1", "Item 2", "Item 3"] # List
4item = random.choice(list) # Chooses from list
5print(item) # Prints choice
6
7# From stackoverflow
8# Tried and tested method
1import random
2randomlist = []
3for i in range(0,5):
4n = random.randint(1,30)
5randomlist.append(n)
6print(randomlist)
1import random
2#Generate 5 random numbers between 10 and 30
3# sample number needs to be smaller than population
4randomlist = random.sample(range(10, 30), 5)
5print(randomlist)