random list python code example
Example 1: 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 2: python function to print random number
import random
n = random.randint(0,22)
print(n)
Example 3: n random numbers python
>>> import random
>>> random.sample(range(1, 100), 3)
[77, 52, 45]
Example 4: python randomly sample entry from a set
import random
random.sample(your_set, number_of_elements)
your_set = {'a', 'bunch', 'of', 'unique', 'words'}
random.sample(your_set, 1)
--> ['words']
random.sample(your_set, 3)
--> ['words', 'of', 'a']
Example 5: select random value from list python
import random
random.sample(list_name, 2)
random.choices(set_name, k=3)
random.choice(list_name)
Example 6: python random liste
import random
liste = ["world, HELLO !", "hello world !"]
N = random.choice(liste)
print(N)