randomize list python code example
Example 1: python shuffle list
import random
number_list = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]
print ("Original list : ", number_list)
random.shuffle(number_list)
print ("List after shuffle : ", number_list)
Example 2: python list of random values
import random
randomlist = random.sample(range(10, 30), 5)
import numpy
random_float_array = numpy.random.uniform(75.5, 125.5, 2)
Example 3: python randomize list
import random
random.shuffle(list)
Example 4: shuffle list
import random
number_list = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]
print("Original list:", number_list)
random.shuffle(number_list)
print("List after first shuffle:", number_list)
random.shuffle(number_list)
print("List after second shuffle:", number_list)
Example 5: randomly shuffle array python
import random
l = list(range(5))
print(l)
lr = random.sample(l, len(l))
print(lr)
print(l)
Example 6: python random generator from list
import random
n = random.random()
print(n)